Gentoo Archives: gentoo-user

From: Willie Wong <wwong@×××××××××.EDU>
To: gentoo-user@l.g.o
Subject: Re: [gentoo-user] tone generator
Date: Thu, 24 Jan 2008 23:43:32
Message-Id: 20080124234458.GA21767@princeton.edu
In Reply to: Re: [gentoo-user] tone generator by maxim wexler
1 On Thu, Jan 24, 2008 at 03:06:38PM -0800, Penguin Lover maxim wexler squawked:
2 > >
3 > > compile it, run it like
4 > >
5 > > ./a.out | play -t raw -s l -f s -c 1 -r 30000 -
6 > >
7 >
8 >
9 > This works, sort of. Sounds like a dentist drill going
10 > in an out.
11 >
12 > heathen@localhost ~/docs/c-prog $ ./a.out | aplay -t
13 > raw -f cdr
14 > Playing raw data 'stdin' : Signed 16 bit Big Endian,
15 > Rate 44100 Hz, Stereo
16
17 This is because the code outputs it as 32 bit signed with 30000 Hz
18 rate. The defaults of aplay is sampling it incorrectly, which is why
19 the file sounds off.
20
21 Now, I think I know what the problem is with sox:
22 1) the commandline syntax changed between 12.* and 14.0, the switches
23 I need should be
24 play -t raw -s -4 -c 1 -r 30000
25 (c.f. man play).
26
27 2) Despite what the man pages say, the '-' switch for reading from
28 stdin seems to be broken. Probably a bug. I'll test more and possibly
29 file a bug report.
30
31 On the other hand, since you have aplay installed, the right syntax
32 should be
33
34 ./a.out | aplay -t raw -f S32_LE -c 1 -r 30000
35
36 Which says to use 32 bit little endian with 1 channel at a sample rate
37 of 30000.
38
39 Unfortunately, if you do that, you won't hear a thing. Why? I got my
40 multiplier wrong in the testing program that I send you. I missed half
41 a byte. Change the definition for coramp (which controls the
42 amplification) to
43
44 int coramp = 0xCFFFFFFF;
45
46 (The reason that I missed half a byte was that I was messing around
47 with harmonics and multiple voicing... so each harmonic needs to be
48 suitably rescaled in amplitude.)
49
50 Hope that helps,
51
52 W
53 --
54 When my cats aren't happy, I'm not happy. Not because I care about their mood
55 but because I know they're just sitting there thinking up ways to get even.
56 ~Penny Ward Moser
57 Sortir en Pantoufles: up 412 days, 22:00
58 --
59 gentoo-user@l.g.o mailing list