ctrulib: getting volume from mic

Discussion in '3DS - Homebrew Development and Emulators' started by mashers, Dec 18, 2015.

  1. mashers
    OP

    mashers Stubborn ape

    Member
    3,837
    5,154
    Jun 10, 2015
    Kongo Jungle
    Hi everyone

    I need to detect the volume of the sound being picked up by the 3DS microphone. I know I can use the functions in mic.h to access the microphone and read data from it, but I can't find a way of measuring the amplitude of what's being sampled. Is there a way?

    Thanks in advance!
     
  2. mashers
    OP

    mashers Stubborn ape

    Member
    3,837
    5,154
    Jun 10, 2015
    Kongo Jungle
    Ok, I've thought some more about this and I think I can use micGetLastSampleOffset() to locate the most recently recorded sample in the recording buffer. Assuming I'm using unsigned 8-bit PCM, I think I can then just read one byte from the buffer starting at the offset to get the data representing the most recently recorded sample. The next problem is how to work out which bits represent the amplitude and which represent the frequency.
     
  3. BurningDesire

    BurningDesire GBAtemp Psycho!

    Member
    4,945
    5,728
    Jan 27, 2015
    United States
    Behind a screen reading news
    What are you planning you glorious bastered O.O
     
    Voxel likes this.
  4. Voxel

    Voxel Clumsy Coder

    Member
    GBAtemp Patron
    Voxel is a Patron of GBAtemp and is helping us stay independent!

    Our Patreon
    5,155
    5,796
    Jun 27, 2015
    United Kingdom
    England, UK
    Fixed.

    Back on topic, isn't there a mic example in the 3DS devkitpro examples?
     
  5. BurningDesire

    BurningDesire GBAtemp Psycho!

    Member
    4,945
    5,728
    Jan 27, 2015
    United States
    Behind a screen reading news
    well screw you too :P

    Yes I think there is.
     
    Voxel likes this.
  6. mashers
    OP

    mashers Stubborn ape

    Member
    3,837
    5,154
    Jun 10, 2015
    Kongo Jungle
    You'll find out soon enough ;)

    There is, but it doesn't seem to work on the latest ctrulib, and in any case it doesn't reveal any information about what was recorded (it just plays it back).
     
    BurningDesire likes this.
  7. machinamentum

    machinamentum GBAtemp Regular

    Member
    163
    450
    Jul 5, 2015
    United States
    If I remember correctly. The mic example writes PCM16 data into the buffer. You can get the last short from the buffer and that signed value would represent your amplitude at that interval (see http://wiki.multimedia.cx/?title=PCM)
     
  8. NicEXE

    NicEXE GBAtemp Fan

    Member
    397
    123
    Dec 6, 2009
    Cyprus
    IS IT A MILKYTRACKER PORT???

    PS. I USED SHIFT, NOT CAPSLOCK
     
    Tomato Hentai likes this.
  9. hobbledehoy899

    hobbledehoy899 Conniption Master

    Member
    2,574
    4,000
    Nov 13, 2015
    United States
    linux-zen
    10/10 well played.
     
  10. NicEXE

    NicEXE GBAtemp Fan

    Member
    397
    123
    Dec 6, 2009
    Cyprus
  11. mashers
    OP

    mashers Stubborn ape

    Member
    3,837
    5,154
    Jun 10, 2015
    Kongo Jungle
    Thank you buddy! I'll take a look into that. For now I can't get the example to work at all (it just hangs when recording).

    ~ø ^† ^ß~æ†

    PS. I USED ALT, NOT CAPSLOCK :P
     
  12. hippy dave

    hippy dave Butts Butts Megabutts

    Member
    2,572
    1,792
    Apr 30, 2012
    Just reading one sample of audio data would be pretty meaningless, as yes it would be a measurement of the signal's amplitude, but only at that arbitrary point in the sound wave. You'll need to use a bunch of sample data in a row to calculate a usable measurement, a common one is RMS, another one is just to use the peak amplitude by keeping track of whichever was the highest point in the range you looked at.
     
  13. chaoszerobillion

    chaoszerobillion Advanced Member

    Newcomer
    79
    22
    Nov 18, 2013
    United States
    Michax
     
  14. TheCruel

    TheCruel Developer

    Banned
    1,351
    2,882
    Dec 6, 2013
    United States
    The mic example in ctrulib works, just tried it a few days ago with latest ctrulib and devkitARM.

    Unfortunately I couldn't make good use of it since I want to use dsp instead of csnd.
     
  15. Rinnegatamante

    Rinnegatamante GBAtemp Psycho!

    Member
    3,127
    3,260
    Nov 24, 2014
    Italy
    Bologna
    I'm quite sure dsp and mic works together (at least on lpp-3ds, but it could be caused by my modification to ndsp wrapper. Normally it uses appcore for dsp channel, i moved it on syscore)
     
  16. mashers
    OP

    mashers Stubborn ape

    Member
    3,837
    5,154
    Jun 10, 2015
    Kongo Jungle
    I only need the amplitude at one point. I'm actually trying to detect the user blowing into the microphone.
     
  17. hippy dave

    hippy dave Butts Butts Megabutts

    Member
    2,572
    1,792
    Apr 30, 2012
    Fair enough :)
     
  18. NicEXE

    NicEXE GBAtemp Fan

    Member
    397
    123
    Dec 6, 2009
    Cyprus
    You crashed my hopes... Here is a sad emoticon :sad:
     
  19. Xenosaiga

    Xenosaiga That one guy that doesn't give a shit anymore

    Member
    1,478
    838
    Oct 9, 2015
    United States
    The Shadows
    I'm gonna take a shot in the dark and guess you are gonna make grid launcher "hop or spin" like the home menu does.