![]() |
#46 |
( ͡° ͜ʖ ͡°){ʇ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
|
snd_pcm_hw_params_set_rate_near not supported
THIS PAGE CONTAINS A COUPLE OF WORKING AUDIO DEMOS, TECHNICAL WAVE DETAILS AND FURTHER ALSA INTIALISATION DETAILS.
=============================================== Threads continue: Code:
/* CAUSES SEGGIE * if ((err = snd_pcm_hw_params_set_rate_near (capture_handle, hw_params, 48000, 0)) < 0) { fprintf (stderr, "cannot set sample rate (%s)\n", snd_strerror (err)); exit (1); } */ Device: hw (type: HW) Access types: MMAP_INTERLEAVED RW_INTERLEAVED Formats: S16_LE S24_LE S20_3LE Channels: 2 Sample rates: 8000 11025 16000 22050 32000 44100 48000 Interrupt interval: 166-512000 us Buffer size: 333-2048000 us Making the right choices should be trivial since we have known hardware (This assumes that all kindles with sound support will support the same alsa rates, This is untested on anything but a 3.) Instead use snd_pcm_hw_params_set_rate For example Code:
if ((err = snd_pcm_hw_params_set_rate (capture_handle, hw_params, 48000, 0)) < 0) { fprintf (stderr, "cannot set sample rate (%s)\n", snd_strerror (err)); exit (1); } Last edited by twobob; 07-11-2012 at 05:55 PM. Reason: added solution - added page precis |
![]() |
![]() |
![]() |
#47 |
( ͡° ͜ʖ ͡°){ʇ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
|
just enough to get you going with mic input.
Here is a simple test program that pulls some data in from the mic and splats it to stderr.
By itself it is, again, almost pointless and feature free but it's enough to get you going with access to mic data. Spoiler:
remember to compile it -lasound and --static against x-compiled alsa-libs ![]() call it like example hw This program is incredibly trivial - it simply output a short buffer of numbers to stderr. The principle in what is important. screenie of the output: ![]() Last edited by twobob; 07-10-2012 at 11:54 AM. Reason: added call info: added mem leak |
![]() |
![]() |
Advert | |
|
![]() |
#48 | |
Carpe diem, c'est la vie.
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 6,433
Karma: 10773668
Join Date: Nov 2011
Location: Multiverse 6627A
Device: K1 to PW3
|
Quote:
|
|
![]() |
![]() |
![]() |
#49 |
( ͡° ͜ʖ ͡°){ʇ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
|
Sound Buffers and Data Transfer
as outlined at http://www.linuxjournal.com/article/6735
A sound card has a hardware buffer that stores recorded samples. When the buffer is sufficiently full, it generates an interrupt. The kernel sound driver then uses direct memory access (DMA) to transfer samples to an application buffer in memory. Similarly, for playback, another application buffer is transferred from memory to the sound card's hardware buffer using DMA. These hardware buffers are ring buffers, meaning the data wraps back to the start when the end of the buffer is reached. A pointer is maintained to keep track of the current positions in both the hardware buffer and the application buffer. Outside of the kernel, only the application buffer is of interest, so from here on we discuss only the application buffer. The size of the buffer can be programmed by ALSA library calls. The buffer can be quite large, and transferring it in one operation could result in unacceptable delays, called latency. To solve this, ALSA splits the buffer up into a series of periods (called fragments in OSS/Free) and transfers the data in units of a period. A period stores frames, each of which contains the samples captured at one point in time. For a stereo device, the frame would contain samples for two channels. Figure 1 illustrates the breakdown of a buffer into periods, frames and samples with some hypothetical values. Here, left and right channel information is stored alternately within a frame; this is called interleaved mode. A non-interleaved mode, where all the sample data for one channel is stored followed by the data for the next channel, also is supported. .... ELIDED ![]() FIGURE 1 This gives us a tidy overview of the way to do our frame maths. We generally use the interleaved format as this is the default it would see, on our setup. There is a wordy explanation of this and corner cases here: http://www.alsa-project.org/main/ind.../FramesPeriods Last edited by twobob; 07-09-2012 at 03:47 PM. Reason: added extra - somewhat wordy - reference |
![]() |
![]() |
![]() |
#50 |
BLAM!
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 13,506
Karma: 26047190
Join Date: Jun 2010
Location: Paris, France
Device: Kindle 2i, 3g, 4, 5w, PW, PW2, PW5; Kobo H2O, Forma, Elipsa, Sage, C2E
|
@twobob: The input twin of dmix is dsnoop, FWIW. Probably not that useful on the Kindle, but, hey
![]() Last edited by NiLuJe; 07-09-2012 at 03:19 PM. |
![]() |
![]() |
Advert | |
|
![]() |
#51 | |
( ͡° ͜ʖ ͡°){ʇ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
|
Glueing inputs together
Quote:
![]() |
|
![]() |
![]() |
![]() |
#52 |
( ͡° ͜ʖ ͡°){ʇ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
|
A simple walkthough
For those looking for a quick, decent short example of a simple blow-by-blow of soundcard through-alsa initialisation on a code level, then you could do worse than this:
http://stackoverflow.com/questions/3...fers-weird-api The final "Answer" is fairly elucidating for those looking for a quick and dirty. Last edited by twobob; 07-09-2012 at 03:49 PM. Reason: added the fact that this is the programmatic detail |
![]() |
![]() |
![]() |
#53 |
( ͡° ͜ʖ ͡°){ʇ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
|
Wave file information
![]() This is called the RIFF structure, built from different 'chunks'. The first 'chunk' is the DESCRIPTOR explaining the RIFF file type. Next the FORMAT 'chunk' which explains the data format. The .WAV sound data can be 8-bit or 16-bit, mono or stereo, can have a different sampling rate, can be compressed or not, etc. The next 'chunk', called the DATA 'chunk' holds the sound data, please see below: ![]() Useful information for strapping together the audio cradle |
![]() |
![]() |
![]() |
#54 |
Connoisseur
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 58
Karma: 63518
Join Date: Apr 2012
Device: KT
|
just for the records
twobob: you are awesome. |
![]() |
![]() |
![]() |
#55 |
Carpe diem, c'est la vie.
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 6,433
Karma: 10773668
Join Date: Nov 2011
Location: Multiverse 6627A
Device: K1 to PW3
|
@twobob: Okay, time to stop hanging out in the "2600 neighborhood". I gave you an extra karma digit (and a palindrome at that).
![]() I like where this is heading. ![]() @MaPePer: I am still looking for a useful contribution from you so you too can join the "2600 club". Got anything to show me? ![]() |
![]() |
![]() |
![]() |
#56 |
( ͡° ͜ʖ ͡°){ʇ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
|
appreciation
I'm not sure what for for, but I'll take it
![]() Thanks. If you mean the "Twobob" music the entire back catalogue of freely-available tracks is here: http://soundcloud.com/twobob/sets/fr...-the-clouders/ ![]() |
![]() |
![]() |
![]() |
#57 |
( ͡° ͜ʖ ͡°){ʇ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
|
This both amuses and educates
![]() Spoiler:
Last edited by twobob; 07-09-2012 at 07:45 PM. Reason: its HUGE |
![]() |
![]() |
![]() |
#58 |
( ͡° ͜ʖ ͡°){ʇ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
|
![]()
THIS IS ONLY TESTED ON A K3 - PLEASE USE THE TONES DEMO FOR OTHER MODELS
I have included here a compiled version of the incredibly obscure http://alumnos.elo.utfsm.cl/~yanez/a...mple-programs/ "microphone" For several reasons, not least the slavish attention to debugging potential. Again, this may have limited uses for the normal folken but give the README a browse. Basically spits out to STDIO again, but with lot's of potential parameters, handy for testing. I made it good for the kindle and managed to remove most of the style warnings. It's not built optimised. the entire code (It's lengthy) Spoiler:
To get around the horrific kernal module crash that appears to rear it's head during piping I currently call my stuff like: (WITH NO LINE BREAKS OBVIOUSLY, I have fixed them up here with \ for visual clarity but you can just call it one one line) Code:
[root@kindle sound]# aplay -D dmix0 ImNotReal.wav;\ ./microphone -d hw:0 -r 16000 -c2 | aplay -f cd -D hw:0 -r 16000 To be clear once again: This extra initial call it to get around a nasty bug that makes the full-duplex hang. This complete call gives us: BE READY TO TURN THE VOLUME DOWN Code:
[root@kindle sound]# aplay -D dmix0 ImNotReal.wav; ./microphone -d hw:0 -r 16000 -c2 | aplay -f cd -D hw:0 -r 16000 ImNotReal.wav: No such file or directory microphone: Device: hw:0 open_mode = 0 microphone: capture method: METHOD_DIRECT_MMAP (m = 1) microphone: Access method: 0 microphone: PCM access method: SND_PCM_ACCESS_MMAP_INTERLEAVED microphone: PCM capture sample format: SND_PCM_FORMAT_S16_LE microphone: Sample_rate_real = 16000 microphone: real_n_channels = 2 microphone: Buffer size = 2048 [frames] Playing raw data 'stdin' : Signed 16 bit Little Endian, Rate 16000 Hz, Stereo But more importantly you can play with the -d,-r and other things you can read about in the README to test capabilities of the device. At the very least this is an exercise in very complete code. As with all my stuff - simply copy it to the device and run it via SSH. The top post covers this in detail I believe. Uninstall - Just delete the file. Last edited by twobob; 07-12-2012 at 11:01 PM. Reason: tidied up the calls. added d/l - added standard install instructions - added point of throwaway call |
![]() |
![]() |
![]() |
#59 |
( ͡° ͜ʖ ͡°){ʇ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
|
![]()
One interesting thing to note is you can monitor devices while the are running:
This output is from running the command whilst the microphone application above is running (Tip: the p in pcm0c is capture, p would be playback) Code:
[root@kindle us]# cat /proc/asound/card0/pcm0c/sub0/hw_params access: MMAP_INTERLEAVED format: S16_LE subformat: STD channels: 2 rate: 44100 (44100/1) period_size: 16 buffer_size: 2048 Cool! Last edited by twobob; 07-09-2012 at 09:14 PM. Reason: added blackness, coolness and rightness |
![]() |
![]() |
![]() |
#60 |
( ͡° ͜ʖ ͡°){ʇ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
|
![]()
Okay, enough initialising. Let's hear something.
First off TURN YOUR VOLUME DOWN. This demo is LOUD. I hope I SHOUTED that enough. I warned you. Next up is the built version of the demo at http://www.alsa-project.org/alsa-doc...c-example.html It plays a simple sine wave to our speaker - pretty dull huh? But it paves the wave for all kind of coolness so here's the blurb Spoiler:
This was the first demo to work out-of-the-box on cross-compile. Happy days. usage: ./sine (it goes up to 5Khz), device hw ( hw:0 and synonyms ) is supported currently install / uninstall: just copy / remove the file Full listing of Usage: sine [OPTION]... [FILE]... -h,--help help -D,--device playback device -r,--rate stream rate in Hz -c,--channels count of channels in stream -f,--frequency sine wave frequency in Hz -b,--buffer ring buffer size in us -p,--period period size in us -m,--method transfer method -o,--format sample format -v,--verbose show the PCM setup parameters -n,--noresample do not resample -e,--pevent enable poll event after each period Recognized sample formats are: S8 U8 S16_LE S16_BE U16_LE U16_BE S24_LE S24_BE U24_LE U24_BE S32_LE S32_BE U32_LE U32_BE FLOAT_LE FLOAT_BE FLOAT64_LE FLOAT64_BE IEC958_SUBFRAME_LE IEC958_SUBFRAME_BE MU_LAW A_LAW IMA_ADPCM MPEG GSM SPECIAL S24_3LE S24_3BE U24_3LE U24_3BE S20_3LE S20_3BE U20_3LE U20_3BE S18_3LE S18_3BE U18_3LE Recognized transfer methods are: write write_and_poll async async_direct direct_interleaved direct_noninterleaved direct_write WHAT IS ACTUALLY ATTACHED IS tones, THIS IS SIMPLY A MORE INTERESTING VARIATION OF THIS CODE. THANKS TESTED ON ALL AUDIO CAPABLE KINDLES Last edited by twobob; 07-12-2012 at 11:03 PM. Reason: I updated the static Alsalib to stop to broken alsa.conf request |
![]() |
![]() |
![]() |
Tags |
stupid root mistakes |
|