• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: How to play RAW PCM data using CoreAudio?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: How to play RAW PCM data using CoreAudio?


  • Subject: Re: How to play RAW PCM data using CoreAudio?
  • From: Brian Willoughby <email@hidden>
  • Date: Thu, 23 Apr 2009 14:22:27 -0700

If your generation code runs fast enough, then you do not need the interim step of saving it in a file. You could use any of the CoreAudio features which use a callback (whether direct audio ouput, or AudioUnit Music Instrument), and simply calculate the data on the fly, providing the samples requested. This would change your makeChirp() slightly, because, rather than loop through all samples, you would only produce the exact number of sample requested in the current callback. Also, you would need to provide subsequent pieces of the waveform for each callback until the chirp is completed - and then you would provide silence to the callback until you want to product another chirp.

Look through the CoreAudio Examples like SinSynth or other callback- based samples for hints.

However, if that proves too difficult, you could change from saving the raw NSData to using the CoreAudio AudioFile API to save a CAF file instead of the raw data. You will certainly be able to open an audio file created with the AudioFIle API (Or ExtAudioFile, if needed).

Brian Willoughby
Sound Consulting


On Apr 23, 2009, at 08:13, malcom wrote:

Hi, I've finally made my own chirp signal and I've written it into a
file (the code is below).
At this time I need to get it played by Core Audio. I've successfully
imported it in Audacity and it works perfectly
(44,100/16bit/mono/endianess)..
I've tried with this code but it does works because seems that CA
can't open raw PCM data file (and inside the list of formats there is
not mention to raw pcm data format).
Anyone can suggest me a way to play it?


void makeChirp(double freq_start,double freq_end,int
duration_secs,long sample_rate, int bits_persample) {
long len_array = (long)duration_secs*sample_rate; // this is the
number of samples to generate
short wavesamples[len_array]; // this is our array of samples
int i; for (i=0; i < len_array; i++) // some funky initializations...
wavesamples[i] = 0;

double k = (freq_end-freq_start)/len_array;
double freq = freq_start; // this is our time-to-time frequency value
double omega = (double)(PI / sample_rate);

long t;
for (t=0; t < len_array; t++) {
freq += k; // increase frequency over the time with the omega value
double c_sample = sin(omega*freq*t)*MAX_INT;
wavesamples[t] = (short)c_sample;
}

NSData *d = [[NSData alloc] initWithBytes: wavesamples length:len_array];
[d writeToFile: @"/Users/malcom/Desktop/file.pcm" atomically:YES];
}


_______________________________________________
Do not post admin requests to the list. They will be ignored.
Coreaudio-api mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden


References: 
 >How to play RAW PCM data using CoreAudio? (From: malcom <email@hidden>)

  • Prev by Date: Re: GrahicEQ AU trouble
  • Next by Date: Convert MP3 data to PCM in iPhone sdk
  • Previous by thread: How to play RAW PCM data using CoreAudio?
  • Next by thread: Convert MP3 data to PCM in iPhone sdk
  • Index(es):
    • Date
    • Thread