How to decode PCM from microphone?

I need to make clap recognition on iPhone.
I know an algorithm how to make it analyzing amplitude-from-time audio signal. But it's not clear for me now how to get such a representation of audio signal from microphone.
Now I only know how to write audio files from microphone:
recorder.h
#import <Cocoa/Cocoa.h>
#import <AudioToolbox/AudioQueue.h>
#import <AudioToolbox/AudioFile.h>
#define NUM_BUFFERS 10
typedef struct {
AudioFileID audioFile;
AudioStreamBasicDescription dataFormat;
AudioQueueRef queue;
AudioQueueBufferRef buffers[NUM_BUFFERS];
UInt32 bufferByteSize;
SInt64 currentPacket;
BOOL recording;
} RecordState;
@interface recorder : NSObject {
@private
BOOL recording;
RecordState recordState;
@property(nonatomic, assign) BOOL recording;
- (void)start;
- (void)stop;
@end
recorder.m
#import "recorder.h"
@implementation recorder
-(void)setRecording:(BOOL)val {
if(val)
[self start];
else
[self stop];
-(BOOL)recording {
return self->recording;
- (id)init {
if (self = [super init]) {
recording = NO;
recordState.dataFormat.mSampleRate = 8000.0;
recordState.dataFormat.mFormatID = kAudioFormatLinearPCM;
recordState.dataFormat.mFramesPerPacket = 1;
recordState.dataFormat.mChannelsPerFrame = 1;
recordState.dataFormat.mBytesPerFrame = 2;
recordState.dataFormat.mBytesPerPacket = 2;
recordState.dataFormat.mBitsPerChannel = 16;
recordState.dataFormat.mReserved = 0;
recordState.dataFormat.mFormatFlags = kLinearPCMFormatFlagIsBigEndian | kLinearPCMFormatFlagIsSignedInteger | kLinearPCMFormatFlagIsPacked;
return self;
- (void)dealloc {
[super dealloc];
void AudioInputCallback(void *inUserData, AudioQueueRef inAQ, AudioQueueBufferRef inBuffer, const AudioTimeStamp *inStartTime, UInt32 inNumberPacketDescriptions, const AudioStreamPacketDescription *inPacketDescs) {
RecordState *recordState = (RecordState *)inUserData;
OSStatus status = AudioFileWritePackets(recordState->audioFile, false, inBuffer->mAudioDataByteSize, inPacketDescs, recordState->currentPacket, &inNumberPacketDescriptions, inBuffer->mAudioData);
if(status == 0)
recordState->currentPacket += inNumberPacketDescriptions;
AudioQueueEnqueueBuffer(recordState->queue, inBuffer, 0, NULL);
- (void)start {
if(!recording) {
self->recording = YES;
recordState.currentPacket = 0;
OSStatus status = AudioQueueNewInput(&recordState.dataFormat, AudioInputCallback, &recordState, CFRunLoopGetCurrent(), kCFRunLoopCommonModes, 0, &recordState.queue);
if(status == 0) {
for(int i = 0; i < NUM_BUFFERS; i++) {
AudioQueueAllocateBuffer(recordState.queue, 16000, &recordState.buffers);
AudioQueueEnqueueBuffer(recordState.queue, recordState.buffers, 0, NULL);
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
NSString *writablePath = [documentsDirectory stringByAppendingPathComponent:@"audio.aiff"];
NSLog(writablePath);
CFURLRef fileURL = CFURLCreateFromFileSystemRepresentation(NULL, (const UInt8 *) [writablePath UTF8String], [writablePath length], NO);
status = AudioFileCreateWithURL(fileURL, kAudioFileAIFFType, &recordState.dataFormat, kAudioFileFlags_EraseFile, &recordState.audioFile);
if(status == 0)
status = AudioQueueStart(recordState.queue, NULL);
if(status != 0)
NSLog(@"Recording Failed!");
- (void)stop {
if(recording) {
self->recording = NO;
NSLog(@"Stopping queue...");
AudioQueueStop(recordState.queue, true);
NSLog(@"Queue stopped");
for(int i = 0; i < NUM_BUFFERS; i++)
AudioQueueFreeBuffer(recordState.queue, recordState.buffers);
AudioQueueDispose(recordState.queue, true);
AudioFileClose(recordState.audioFile);
NSLog(@"Audio file closed");
@end
I have an idea to replace AudioFileWritePackets in callback AudioInputCallback. And that inBuffer->mAudioDataByteSize bites from pointer inBuffer->mAudioData will be amplitude-time signal representation... But I do not know how to decode that memory area: looks like I need to work with a pairs of bites (mBytesPerPacket = 2). May I represent them as one of "standart" types (like int)? Is it signed or not?

hi, Have you solve the problem ? I am interesting in this field too .

Similar Messages

  • How to acquire sound from microphone using Sound & Vibration toolkit

    Hello All,
    I need to know how we can acquire signals from microphone using S&V toolkit.

    Hi pmg,
    If you have the Sound and Vibration Measurement Suite installed, you may want to take a look at the examples here:
    <LabVIEW Directory>\examples\Sound and Vibration\Audio Measurements
    Thanks as kudos only

  • How to decode a set of datas received from serial port and display image on a canvas based on CVI ?

    Hi !
    I have received a set of datas via rs232 and it contains picture messages. I have to decode the datas first and then display them on a canvas.
    I have known several functions that may be used . Such as
    int SetBitmapData (int bitmapID, int bytesPerRow, int pixelDepth, int colorTable[], unsigned char bits[], unsigned char mask[]);
    int CanvasDrawBitmap (int panelHandle, int controlID, int bitmapID, Rect sourceRectangle, Rect destinationRectangle);
     However,I don't know how to set the following parameters according to the actual pixel values and color values.
    int bytesPerRow, int pixelDepth, int colorTable[], unsigned char bits[], unsigned char mask[]
     What's more,I have no idea how to decode the datas.
    The  attachment is a incomplete project. I will be very appreciated if anyone could help me .
    Best regards.
    xiepei
    I wouldn't care success or failure,for I will only struggle ahead as long as I have been destined to the distance.
    Attachments:
    Decode and display image.zip ‏212 KB

    Well, things are getting a bit clearer now.
    1. Your image is actually 240x240 pixel (not 320x240 as you told before). The size of image data is 57600 bytes which corresponds to that frmat (I was puzzled by such a data size compared with larger image dimensions!)
    2. The image is a 8-bits-per-pixel one; this means that you must provide a color palette to create the bitmap
    3. You cannot simply copy image data into bitmap fields in CVI: CreateBitmap always produce an image with pixeldepth matched with display colour depth (normally 24 or 32 bpp)
    All that means that you must:
    1. Create the appropriate color palette with 256 colors: it may be a grayscale or color palette depending on camera characteristics. Grayscale palette can be found in my sample project, while sample colour palettes can be found here (here the description of a "standard" 8-bpp color palette)
    2. Create the bits array correctly dimensioned for the color depth of your monitor
    3. Get each pixel value from the camera, lookup in the color palette for the appropriate colour and create the RGB informations into the bits array in memory
    4. Display the bitmap on the canvas
    As a first step, I would configure my system for 256-color display setting, create a bitmap and simply copy image data into it: you should be able to get the correct image back to your screen.
    Proud to use LW/CVI from 3.1 on.
    My contributions to the Developer Zone Community
    If I have helped you, why not giving me a kudos?

  • How do I get my microphone to work in bootcamp? It is from the earbuds I use for my iPhone.

    How do I get my microphone to work in BootCamp? It is from the earbuds I use for my iPhone.

    There must be a way to get it to work... I mean it works fine in Mac OS X so there has to be a way to tweak it to work in Windows... right?
    I really like using my iPhone headset, it's a bummer it doesn't work

  • How to decode a base64 image that is parsed from an xml

    Hi everyone,
    I'm trying to decode a base64 image that is parsed from an XML. I was able to decode everything except for an image, and it resulted in weird characters such as
    ������?��������?��������f����������?
    I used sun.misc.BASE64Decoder()
    Thanks in advance,
    Squid

    Hi,
    I know that those are wierd characters because I have the correctly decoded data, and it looks different. Does any one know how to decode against the ASCII
    I know the following code would decode my base64 image correctly, but i dont know how to do the same in java for the follwing C# line of code:
    System.Web.HttpUtility.UrlDecode(sXMLString,
    System.Text.Encoding.GetEncoding(1252));
    Below is the entire C# code that successfully decode the base64 image from " test9.xml"
    using System;
    using System.Collections.Generic;
    using System.IO;
    using System.Text;
    using System.Xml;
    using System.Web;
    namespace DecodeXML
    class Program
    static void Main(string[] args)
    string sFileName = "test9.xml";
    string sXMLString = File.ReadAllText(@"C:\NET 2.0 Projects\ThrowAways\SampleLabels\" + sFileName);
    string resultString =
    System.Web.HttpUtility.UrlDecode(sXMLString,
    System.Text.Encoding.GetEncoding(1252));
    XmlDocument oXML = new XmlDocument();
    oXML.LoadXml(resultString);
    XmlNode oLabel = oXML.SelectSingleNode("//LabelBody");
    // removed the line that saved it to a string variable, because it converts the binary characters to
    // incorrect text representations. However, by saving the bytes directly rectifies this
    File.WriteAllBytes(@"C:\NET 2.0 Projects\ThrowAways\SampleLabels\" + sFileName + ".txt", Convert.FromBase64String(oLabel.InnerText));
    Any suggestion is strongly appreciated.
    Thanks,
    Squid

  • How can I send sound from microphone to Bluetooth speakers?

    How can I send sound from microphone to Bluetooth speakers? They work from the music app but not from an internal or external microphone.  Is this a setup issue or is there a work around?

    I don't know of any way to do that.

  • How to capture and save voice from microphone

    I'm beginner to JMF. I want coding for capturing and saving voice from microphone. Plz anybody help me.

    http://javasolution.blogspot.com/2007/04/voice-chat-using-java.html
    http://www.vsj.co.uk/java/display.asp?id=370

  • Figuring out how to extract images from a PDF file

    Hi,
    I'm trying to write a small app that extracts all images from a PDF file. I already wrote a nice parser and it works good but the only problem is that I can't quite figure out from the reference how to decode all images in a PDF file to normal files such as tiffs, jpegs, bmps etc. For now I'm focusing on XObject images and not dealing with inline images.
    From what I understand so far just by trying and looking at open sources I figured that if I see a XObject Image with a DCTDecode filter, taking the stream data without doing anything to it and saving it as a jpeg file works. But doing the same to FlateDecoded streams or CCITTFax didn't work.
    What is the right way to properly extract the images?

    In general you have to
    * decode the stream
    * extract the pixel data
    * use ColorSpace, BitsPerComponent, Decode and Width to unpack pixel
    values
    * reconstruct an image file format according to its specification
    There are no other shortcuts. The DCTDecode shortcut (which doesn't
    work for CMYK JPEG files) is just a piece of fantastic good luck.
    Aandi Inston

  • Realtime recording from microphone to network

    Greetings,
    I've been trying to figure out how I can record from the microphone and process it straight to network. For instance, I would like to stream or upload as I have the mic recording. I saw this capability mentioned in the Apple documentation but I haven't seen any example code in doing this.
    This is the excerpt:
    "When you record using Audio Queue Services, the destination can be just about anything—an on-disk file, a network connection, an object in memory, and so on.
    From: http://developer.apple.com/iphone/library/documentation/MusicAudio/Conceptual/Au dioQueueProgrammingGuide/AQRecord/RecordingAudio.html
    I could probably use parts of the "SpeakHere" example code but I'm lost to see how to connect the output to my server. If anyone could point me in the right direction I'd really appreciate it.
    Thanks!
    Pat

    orangekay - thanks for the response! I guess that's what I would need help with as well. I'm not exactly sure the format that I would need. Ideally, something small... the recordings would only be about 20 seconds max. I'm not sure if I could do such a thing with HTTP requests or if I would have to have the client connect to a socket on my server to send the data too... any insight would be great.
    Pat

  • How to "decode" picture attachments to emails

    I get lots of family pic attached to emails but I cannot get them into PSE10 apparently because I did not decode them correctly. -- ??

    Thank you.
    If my people, who are called by my name, will humble themselves and pray and seek my face and turn from their wicked ways, then will I hear from heaven and will forgive their sin and will heal their land. 2Chron.7:14
    hyadav <[email protected]> wrote:
    =============
    hyadav http://forums.adobe.com/people/hyadav created the discussion
    "Re: how to "decode" picture attachments to emails"
    To view the discussion, visit: http://forums.adobe.com/message/5261505#5261505

  • How can I set the microphone input level?

    How can I set the microphone input level?

    It would be best to use the standard windows mixer "sndvol32.exe" (in the windows directory) and control it with the System Exec.vi from the Communication palette.
    You may want to look at the following discussion thread, too:
    how to control the microphone volume input via LabView
    How Can I Record Sound in LabVIEW from Sources other than the Microphone?
    Zvezdana S.

  • Urgent need: how to decode usr02

    On my laptop sandbox, I can see the password in table usr02 but
    in an encrypted form.
    Could you tell me how to decode the password?
    Thanks and points.

    This would lock the user.
    Did you check the value of login/no_automatic_usr_sapstar?
    (should be 0, otherwize the system will not recreate the sap* user)
    You may also try (the last option that is avaible):
    if you have another system (for example PROD),
    you can over-ride the password of your users (field bcode in usr02)
    from the system you know the password.
    p.s
         you can not copy password of diffrent user,
         e.g: user A has password "ABCDE",
         user B has password "ABCDE",
         the values of the BCODE in usr02 would be diffrent from user A to B
                    although they thave the same passord,
                    this is because the encryption is per user,
                    however, user A that have the password "ABCDE"
                    in diffrent systems/client will have the same BCODE
                    (the encryption algoritem uses only the user-name to encrypt)

  • How to export video from camera to ipad

    How to export video from camera to ipad

    Pad2, the new iPad Supported Video Formats & Movie Formats
    H.264 video up to 1080p, 30 frames per second, High Profile level 4.1 with AAC-LC audio up to 160 Kbps, 48kHz, stereo audio in .m4v, .mp4, and .mov file formats;
    MPEG-4 video up to 2.5 Mbps, 640 by 480 pixels, 30 frames per second, Simple Profile with AAC-LC audio up to 160 Kbps per channel, 48kHz, stereo audio in .m4v, .mp4, and .mov file formats;
    Motion JPEG (M-JPEG) up to 35 Mbps, 1280 by 720 pixels, 30 frames per second, audio in ulaw, PCM stereo audio in .avi file format
    You can use a USB flash drive & the camera connection kit.
    Plug the USB flash drive into your computer & create a new folder titled DCIM. Then put your movie/photo files into the folder. The files must have a filename with exactly 8 characters long (no spaces) plus the file extension (i.e., my-movie.mov; DSCN0164.jpg).
    Now plug the flash drive into the iPad using the camera connection kit. Open the Photos app, the movie/photo files should appear & you can import. (You can not export using the camera connection kit.)
     Cheers, Tom

  • How to get event from message?

    Hi,All:
    I write a run-time interface by CVI, I use TS_EngineRegisterUIMessageCallback to register my callback function, but when message passed to the callback function, as the type is struct IDispatch but not CAObjHandle, I don't know how to read event from message.
    Can you help me to solve it? Thanks
    Chang Zhang

    Hello Chang-
    If your question is simply how to obtain an object handle from an object of type IDispatch, have you investigated the function "CA_CreateObjHandleFromIDispatch"? I would recommend you look over the testexec.prj that is installed along with the TestStand engine (the CVI Operator Interface) and inspect how we handle our callbacks, this may help you understand how to go about emulating the behavior in your own project. To see this particular function in use it may be most helpful to look in the file 'engine.c' and inside the function UIMessageDeferredCallback here you will see the IDispatch pointer being handled and decoded for use by the TS engine.
    Regards,
    Elaine R.
    Applications Engineering
    National Instruments
    http://www.ni.com/ask

  • Passing data from Microphone to FFT (Fast Fourier Transform) Class

    I am quite new to Java and trying to find a way to use microphone and pass the data from microphone to a FFT Class and get the result back as one number (which will be the frequency). Because I am quite new, I am in need of some advice and description to solve this problem.
    I will be glad if anybody experienced on this issue can help me.
    Regards.

    You need to read a good bit about signal analysis before you tackle this.
    The FFT is an algorithm for the implementation of the Discret Fourier Transform (DFT). If you just perform an FFT of your data how are you then going to extract the frequency. For example, if you take the DFT of 1024 samples you will generate 1024 complex values with the to 512 pairs being complex conjugates of the bottom 512 pairs.
    If you just choose the frequency with the largest magnitude then you will suffer from 'windowing' effects. You will need first to apply a 'window 'to your data so as to minimize the effects of only being able to use a limited length of data.
    OK, so you have applied a window, performed the DFTand found the sample with the largest magnitude then how do you relate this frequency index to the real frequency?
    If you Google for Java FFT I know you will be able to find an FFT implementation but that is just the start. You need to understand the DFT and how to use it and what it's limitations are and how to relate the results to the real world. You almost certainly cannot get that information from a Java forum. Java forums are for dealing with specific Java problems.
    So! Go study some signal analysis before you start using the FFT on your microphone data.
    A few words of warning. If you download an FFT implementation, make sure you test it extensively before you use it on your real data. I have tested about 10 and there are some rubbish implementations out there.

Maybe you are looking for

  • Resizing Image and Not Keep Aspect Ratio

    Is there a free program to resize images and not keep the original aspect ratio? I need to resize loads of images to 100x100 pixels and have tried Image well and IResize yet they do not seem to have an option to not keep the original aspect ratio. Th

  • RH Server 7 and Adobe Technical Communication Suite

    Does anybody know if RH server 7 is included in the Technical Communication Suite? I have not seen it mentionned anywhere.... Thanks!

  • Should I duplicate existing objects in designer

    Hi, I have existing webi doc reports running fine on exisitng objects in universe. I have foll tables joined: DailySales   -> CompanyCalendar | > SalesCommission From above I can compile sales commission montly. For a new requirement, a now have a ta

  • Picture Gallery Display

    Ok, I've got my website up and running with a few galleries on for my photography work. Nine images to a page, in a grid, with the pretty slideshow if you click on the slideshow button. But by accident I just clicked on a photo, and I got a big photo

  • Portal Runtime Error for "toolAreaiView"............??

    Hi all, We are using EP6 SP11 Patch3 installed on UNIX. We are getting following error message after some time: Portal Runtime Error An exception occurred while processing a request for : iView : pcd:portal_content/com.lti.I-1192_fldr_01/ com.lti.I-1