![]() |
#1 |
Carpe diem, c'est la vie.
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 6,433
Karma: 10773668
Join Date: Nov 2011
Location: Multiverse 6627A
Device: K1 to PW3
|
geekmaster's sound demo thread
Here, I will post a series of sound demos for the eink kindles (except the soundless K4). To begin, I present here a simple sound demo with relatively little code compared to other sound programs, and it even works on all kindles I tested it on (and probably the Raspberry Pi too).
![]() ![]() geekmaster's noisy rhythms audio demo This simple kindle sound demo plays a noisy rhythm on your eink kindle speakers (or headphones). To play this sound demo, just download and extract "noisy" (below), then copy it to your kindle USB drive, then run it (SSH, or with a launcher). It will stop automatically when finished. Yeah, it is really nothing fancy, but now you can use your kindle to annoy others in the room with you. ![]() The source code: Spoiler:
After cross-compiling the latest 1.0.25 ALSA sound library on my linux host PC (from source, with static-linking support), I used it to compile "noisy.c" with this command: arm-linux-gcc -o noisy noisy.c -lasound Geekmaster "noisy rhythms" Demo, Sound Synthesis Algorithm, Theory of Operation: Spoiler:
Now that we have simple audio support for native mode programs (on all eink kindles except the soundless K4), our next step is to integrate it into gmplay (geekmaster's kindle video player). Then we get to encode movies with sound. Then YOU get to play (and listen to) those movies. ![]() EDIT: K4 owners, never fear, there are plans to add USB sound support to your K4 too, using the same methods already being used for the Nook Simple Touch (a short $0.97USD USB host mode cable, a $1.35USD USB sound stick, and some free software). We just need to borrow a little code from the Nook Simple Touch forums. ![]() ![]() The download files: Last edited by geekmaster; 07-13-2012 at 01:52 PM. |
![]() |
![]() |
![]() |
#2 |
Carpe diem, c'est la vie.
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 6,433
Karma: 10773668
Join Date: Nov 2011
Location: Multiverse 6627A
Device: K1 to PW3
|
Building sound demos like "noisy" on the kindle with tcc would require some missing files needed for "tccmake noisy -lasound" to succeed. These files could probably be copied to the kindle from the host PC cross-compiler "include" and "alsa" directories. "Somebody" really ought to try that at some point (in the near future).
![]() Last edited by geekmaster; 07-13-2012 at 08:46 AM. |
![]() |
![]() |
Advert | |
|
![]() |
#3 |
( ͡° ͜ʖ ͡°){ʇlnɐɟ ƃǝs}Tır
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 6,586
Karma: 6299991
Join Date: Jun 2012
Location: uti gratia usura (Yao ying da ying; Mo ying da yieng)
Device: PW-WIFI|K5-3G+WIFI| K4|K3-3G|DXG|K2| Rooted Nook Touch
|
Bing bang bong
HA! Quality.
*Goes off to test Okay first thoughts. by calculating the realtime speed of the bits at your chosen rate you could swap in fixed sections of 0's modulo something. I see you already use &3 so something of this order again I would imagine. That would still be programmatically tidy and would create real percussive effects ![]() I'm going to have a play now and see if I can implement what I'm talking about. Sweet abbreviation of the init. Pretty snappy huh! Last edited by twobob; 07-13-2012 at 07:30 AM. Reason: added a thought, more notes |
![]() |
![]() |
![]() |
#4 |
Carpe diem, c'est la vie.
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 6,433
Karma: 10773668
Join Date: Nov 2011
Location: Multiverse 6627A
Device: K1 to PW3
|
As you can see (and hear), random() as used in this "noisy" demo gives an amplitude modulated "semi-percussive" sound effect, while sin() as used in twobob's "tones" demo gives pure unmodulated sine wave tones.
The question still stands though: If sin() gives sine wave tones, would replacing it with (x*x) give "square wave" tones? ![]() Last edited by geekmaster; 07-13-2012 at 08:31 AM. |
![]() |
![]() |
![]() |
#5 | |
Carpe diem, c'est la vie.
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 6,433
Karma: 10773668
Join Date: Nov 2011
Location: Multiverse 6627A
Device: K1 to PW3
|
Quote:
![]() Personally, I think it is much easier to study and understand my sound code shown above (click the "Show" button to see it) than it is to study or understand your "knc1-friendly Astyle" formatted version of your tones demo, with the "Horrible!" amount of vertical scrolling required. ![]() |
|
![]() |
![]() |
Advert | |
|
![]() |
#6 |
( ͡° ͜ʖ ͡°){ʇlnɐɟ ƃǝs}Tır
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 6,586
Karma: 6299991
Join Date: Jun 2012
Location: uti gratia usura (Yao ying da ying; Mo ying da yieng)
Device: PW-WIFI|K5-3G+WIFI| K4|K3-3G|DXG|K2| Rooted Nook Touch
|
For my part I would like to see it documented to indicate why you used certain values or number types to constrain number ranges.
unsigned char buf[1024]; // play buffer (Matches output blah blah) That type of information is vital - like - "chose u-chars for my buffer so the output value of 0 - 255 would exactly match my sample types u8 maximum range." at least in a note somewhere. "Type equivalences for the 16 bit sample range would be BLAH" It's these type of implementation details that give a newbie developer insight into making what is "already there" work for better for them. Plus it documents them for everyone. including you. I am all for the condensed style for demo code - with notes available. or the longer more documented style for walkthroughs. There is a middle ground of course and that is where most of us live. ![]() I am fiddling with swapping in a known length of 0's at a known rate to give perceptual tempo. Good fun! |
![]() |
![]() |
![]() |
#7 | |
Carpe diem, c'est la vie.
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 6,433
Karma: 10773668
Join Date: Nov 2011
Location: Multiverse 6627A
Device: K1 to PW3
|
Quote:
If this had been a "musical synthesis" demo, I would have tried to show what was going on in the "magic formulas". This is so simple I did not think that necessary, but because you are "into" music, I will do that now... Done! I added a "Theory of Operation" section for the tiny sound synthesis formula to the Top Post. Regarding internal documentation, I use a little inline commenting where needed, and I document the important variables that you may want to change with inline comments where they are defined. But stuff that is "just there" to be used and not changed, I like to "black box" so it does not distract from the "important" stuff. Feel free to create fully comment hybrid-style source code that has more documentation if you want, but I would rather move on to the next incremental step in my evolution of native mode sound software for the eink kindles. I got a lot of professional criticism by colleagues over the years for "too many comments" in my code, so now I try to make my code small, simple, and self-evident, so it only needs minimal comments to guide you through it (with the help of RTFM on the "standard" function call parameters and data structures). Last edited by geekmaster; 07-15-2012 at 01:46 AM. |
|
![]() |
![]() |
![]() |
#8 | |
( ͡° ͜ʖ ͡°){ʇlnɐɟ ƃǝs}Tır
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 6,586
Karma: 6299991
Join Date: Jun 2012
Location: uti gratia usura (Yao ying da ying; Mo ying da yieng)
Device: PW-WIFI|K5-3G+WIFI| K4|K3-3G|DXG|K2| Rooted Nook Touch
|
Thanks GM
Quote:
In other news I think I finally managed to x-compile alsa... ![]() |
|
![]() |
![]() |
![]() |
#9 | |
Carpe diem, c'est la vie.
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 6,433
Karma: 10773668
Join Date: Nov 2011
Location: Multiverse 6627A
Device: K1 to PW3
|
Quote:
![]() I had to copy the freshly built alsa files into my toolchain directories before I could compile sound apps. Sadly, WHERE to put the alsa header file varies in various examples. Some use the default /include folder (like I used in the "noisy" demo), and others prefix it with alsa/ inside the #include (like you did in the "tones" demo). Perhaps it would be good to copy that header to BOTH places in the toolchain folders, so both demos can compile as-is... EDIT: Regarding coding style and documentation: As you can see, it took 1542 characters of comments to precisely describe the operational theory of the "(random()&3)*i*350" logical expression used to stuff values into the sound buffer. Describing my much larger dithering expressions would take MUCH more effort (and words). I think that injecting those comments (and more) into my condensed code may somewhat interfere with how much REAL code fits "above the fold" (i.e. no vertical scrolling). It would also spread related code segments so far apart that relational perception would be severely degraded while "absorbing" the code. Remember, all of the BEST programmers are "trance coders", and need to absorb the structure and nuances of the code IN PARALLEL. Just read some biographies of famous software programmers and you will see what I mean. For a great little introduction to trance coding, read this: http://www.wintermute.me.uk/writing/coding-trance.html Last edited by geekmaster; 07-13-2012 at 12:03 PM. |
|
![]() |
![]() |
![]() |
#10 | |
( ͡° ͜ʖ ͡°){ʇlnɐɟ ƃǝs}Tır
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 6,586
Karma: 6299991
Join Date: Jun 2012
Location: uti gratia usura (Yao ying da ying; Mo ying da yieng)
Device: PW-WIFI|K5-3G+WIFI| K4|K3-3G|DXG|K2| Rooted Nook Touch
|
x086
Quote:
I recall programming a tarot program a zillion moons ago for an x086 series, it was a requirement back then to have a decent structure in your head given the limited resources before you started. Times really haven't changed that much all in. The notes were helpful. : ) |
|
![]() |
![]() |
![]() |
#11 |
( ͡° ͜ʖ ͡°){ʇlnɐɟ ƃǝs}Tır
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 6,586
Karma: 6299991
Join Date: Jun 2012
Location: uti gratia usura (Yao ying da ying; Mo ying da yieng)
Device: PW-WIFI|K5-3G+WIFI| K4|K3-3G|DXG|K2| Rooted Nook Touch
|
the ALSA folder is a parent-referencing sym link.
Put it in the root and let it sort itself out. |
![]() |
![]() |
![]() |
#12 | |
Carpe diem, c'est la vie.
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 6,433
Karma: 10773668
Join Date: Nov 2011
Location: Multiverse 6627A
Device: K1 to PW3
|
Quote:
I did not make that connection until now that I saw your explanation. ![]() Regarding helpful notes, I have often put the "theory of operation" inside the README file for smaller commercial programs (or an operating manual appendix for significant works). But this is a hobby, so Theory of Operation is done only if the thing being taught depends on it (or on request, as in this case). ![]() Last edited by geekmaster; 07-13-2012 at 12:26 PM. |
|
![]() |
![]() |
![]() |
#13 | |
( ͡° ͜ʖ ͡°){ʇlnɐɟ ƃǝs}Tır
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 6,586
Karma: 6299991
Join Date: Jun 2012
Location: uti gratia usura (Yao ying da ying; Mo ying da yieng)
Device: PW-WIFI|K5-3G+WIFI| K4|K3-3G|DXG|K2| Rooted Nook Touch
|
Quote:
At the end of the day I would rather you spent more time making awesome things and less time writing notes because from a purely selfish level I would - by proxy and your generous nature - gain access to more awesome things more quickly. That said, even I was scratching my head why you were bottom trimming the bits and range wrapping the numbers (was it distortion effect? is it an oversight?), in essence breaking the numeric link between range and outputted range makes it tough for someone making the transition from thinking in analogue to digital. I myself am guilty of such range wrapping (as you may have noted) in the tones demo to get quick and dirty access to "awesome". Just thought I would point out that the link between total available numeric range and the ability to flaunt that constraint to make it do awesome maybe needed pointing out in this instance. bitwise truncation and range wrapped distortion are not exactly entry-level audio-theory subjects (well, they are actually, but you know what I mean) Thanks for making it nice and clear. In other news: I have indeed got my plughw etc interfaces back. Happy days. Last edited by twobob; 07-13-2012 at 12:26 PM. Reason: twypos |
|
![]() |
![]() |
![]() |
#14 |
( ͡° ͜ʖ ͡°){ʇlnɐɟ ƃǝs}Tır
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 6,586
Karma: 6299991
Join Date: Jun 2012
Location: uti gratia usura (Yao ying da ying; Mo ying da yieng)
Device: PW-WIFI|K5-3G+WIFI| K4|K3-3G|DXG|K2| Rooted Nook Touch
|
Hmm. u8? I wonder what I could get that to sound like with movie sound tracks...
*gets out some tools* 46 min of audio: 1152 MB @ 44k 16bit stereo 86.2MB @ 8k 16bit stereo 43.1 MB @ 8K 16 bit mono Raw is 42.1 on the disk. I'm going to try to squish it down to @ 8k 8 bit mono. see what I get - should be two timesless or something. If I could get that listenable...I'll see if I can get the noise shaping right... Could be useful EDIT: Yes. It's 21 MB uncompressed. 12.9 MB in a tar.gz. so basically 100 times smaller? not bad. Last edited by twobob; 07-13-2012 at 12:54 PM. Reason: added numbers - and italics |
![]() |
![]() |
![]() |
#15 |
Carpe diem, c'est la vie.
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 6,433
Karma: 10773668
Join Date: Nov 2011
Location: Multiverse 6627A
Device: K1 to PW3
|
For A/V movies, we will probably need more Theory of Operation when we start using pthreads so that one thread can be stuck in the eink update syscall while the other thread is stuck in the sound buffer write library call. And maybe a third thread to run the GUI.
![]() And u8 (unsigned 8-bit) mono audio should be fine for tiny little speakers. The viewer will be distracted by the video anyway. Of course, using quality headphones while watching music videos may be a little dissapointing on both the audio and the video, in which case an eink kindle is clearly the wrong platform. So yes, u8 audio is quite appropriate for long persistence low framerate eink dithered monochrome video, I think... ![]() And besides, the relatively simple C code public domain cellphone codec I am porting for the gmv mono audio track is only 8-bit. ![]() Of course, 8-bit audio needs an audio compander algorithm (dynamic range compression) to avoid severe distortion on low volume audio passages or clipping (fuzz box) on high volume audio sound effects. Last edited by geekmaster; 07-13-2012 at 01:07 PM. |
![]() |
![]() |
![]() |
Tags |
geekmaster audio sound |
|
![]() |
||||
Thread | Thread Starter | Forum | Replies | Last Post |
geekmaster formula 42 (the dithermatron demo) | geekmaster | Kindle Developer's Corner | 65 | 03-17-2017 08:51 AM |
geekmaster vacation | geekmaster | Kindle Developer's Corner | 2 | 03-19-2012 09:18 PM |
Demo: Jetbook mini official demo | bookwarm | Ectaco jetBook | 36 | 09-21-2010 12:18 PM |