Re: Bitperfect Ears

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On 27-11-07 02:26, Rene Herman wrote:

Wrote a small sine generator during this test by the way -- attached just in case anyone is interested. Writes S16_LE to stdout, so intended to be used as:

$ sine -f <freq> -d <dbspl> | aplay -f cd

-r <rate> for setting a different rate than 44100:

$ sine -f <freq> -d <dbspl> -r <rate> | aplay -f S16_LE -c 2 -r <rate>

Sigh, did it again...

s/#ifdef __LITTLE_ENDIAN/#if __BYTE_ORDER == __LITTLE_ENDIAN/

By the way, I should also really comment that NOONE SHOULD listen TO ANYTHING, INCLUDING SINE WAVES, AT HIGH LEVELS.

Most setups will be perfectly capable of damaging on's hearing, so always be careful. This program generates 0 dBFS (LOUDEST!) samples by default, so if anyone tries something, turn things down first!

And yes, I'd generally assume that people aren't idiots, but it's probably good to warn anyway given that this is being posted in the context of hearing tests and all...

Rene
/*
 * Generates a stereo S16_LE sine at settable rate, frequency and dBFS
 *
 * gcc -W -Wall -o sine sine.c -lm
 */

#include <stdlib.h>
#include <stdio.h>
#include <stdint.h>
#include <math.h>

#include <unistd.h>

#define RATE_MIN	8000
#define RATE_MAX	192000

#define FREQ_MIN	20
#define FREQ_MAX	30000

#define DBFS_MIN	-((16 * 20 * M_LN2) / M_LN10)
#define DBFS_MAX	0

#define RATE		44100
#define FREQ		440
#define DBFS		0

static inline uint16_t le(uint16_t val)
{
#if __BYTE_ORDER == __LITTLE_ENDIAN
	return val;
#else
	return bswap_16(val);
#endif
}

int main(int argc, char *argv[])
{
	int rate = RATE;
	int freq = FREQ;

	double dbfs = DBFS;
	double ampl;

	int i;
       
	while ((i = getopt(argc, argv, "r:f:d:")) != -1) {
		char *endptr;

		switch (i) {
		case 'r':
			rate = strtol(optarg, &endptr, 0);
			if (rate < RATE_MIN || rate > RATE_MAX || *endptr)
				goto usage;
			break;
		case 'f':
			freq = strtol(optarg, &endptr, 0);
			if (freq < FREQ_MIN || freq > FREQ_MAX || *endptr)
				goto usage;
			break;
		case 'd':
			dbfs = strtod(optarg, &endptr);
			if (dbfs < DBFS_MIN || dbfs > DBFS_MAX || *endptr)
				goto usage;
			break;
		default:
			return EXIT_FAILURE;
		}
	}

	if (rate < 2 * freq) {
usage:
		printf("usage: %s [-r <rate>] [-f <freq>] [-d <dbfs>]\n", argv[0]);
		return EXIT_FAILURE;
	}

	ampl = 32767.0 / pow(10, -dbfs / 20);
	while (1)
		for (i = 0; i < rate; i++) {
			uint16_t sample = le(ampl * sin(((2 * i * freq) * M_PI) / rate));

			write(STDOUT_FILENO, &sample, sizeof sample);
			write(STDOUT_FILENO, &sample, sizeof sample);
		}

	return EXIT_SUCCESS;
}
-------------------------------------------------------------------------
This SF.net email is sponsored by: Microsoft
Defy all challenges. Microsoft(R) Visual Studio 2005.
http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/
_______________________________________________
Alsa-user mailing list
Alsa-user@xxxxxxxxxxxxxxxxxxxxx
https://lists.sourceforge.net/lists/listinfo/alsa-user

[Index of Archives]     [ALSA Devel]     [Linux Audio Users]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [Yosemite Photos]     [KDE Users]     [Fedora Tools]

  Powered by Linux