• 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: converting audio signal to buffer value
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: converting audio signal to buffer value


  • Subject: Re: converting audio signal to buffer value
  • From: Roland Silver <email@hidden>
  • Date: Wed, 26 Mar 2008 19:34:33 -0600

"Use AudioConverter" is vague. Just how do I use it? Here is my callback and its ancillary function renderSignal:
--------------------------------------------
OSStatus callback(
void *inRefCon,
AudioUnitRenderActionFlags *ioActionFlags,
const AudioTimeStamp *inTimeStamp,
UInt32 inBusNumber,
UInt32 inNumberFrames,
AudioBufferList *ioData)
{
renderSignal(
inNumberFrames,
ioData,
sSampleRate,
sToneFrequency,
sWhichFormat);
return noErr;
} //end callback
--------------------------------------------
void renderSignal (
UInt32 inFrames,
AudioBufferList *ioData,
double inSampleRate,
double plangency,
int inOutputFormat) {
double t = getTime();
double dt = 1.0/inSampleRate;
// mNumberBuffers is the same as the kNumChannels
UInt32 frame;
StereoSignal ssignal;
for (frame = 0; frame < inFrames; ++frame) {
// generate inFrames 32-bit floats
ssignal = (signalType ? getSineSignal(t) : getPieceSignal(t));
((SInt16*)((&(ioData->mBuffers[0]))->mData))[frame] =
(SInt16)(ssignal.left * plangency * 32768. + 0.5);
((SInt16*)((&(ioData->mBuffers[1]))->mData))[frame] =
(SInt16)(ssignal.right * plangency * 32768. + 0.5);
t += dt;
} //end for
setTime(t);
} //end renderSignal
--------------------------------------------


On 2008Mar26, at 19:15, William Stewart wrote:
Use AudioConverter - its very optimised for these kinds of transformations


AudioConvertConvertBuffer or AudioConverterFillComplexBuffer


Bill

On Mar 26, 2008, at 3:45 PM, Roland Silver wrote:
If I have an audio signal as a double in the range -1.0 to 1.0, what is the proper way to convert it to an integer (SInt16?) as a value to be entered into an audio buffer?


I tried this, but it resulted in horrible distortion:
((SInt16*)((&(ioData->mBuffers[0]))->mData))[k] = (SInt16)(signal * 32768.0 + 0.5);


Roland Silver
email@hidden


_______________________________________________ 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
  • Prev by Date: Re: converting audio signal to buffer value
  • Next by Date: Re: MIDI driver hibernation problem
  • Previous by thread: Re: converting audio signal to buffer value
  • Next by thread: simplest sound output
  • Index(es):
    • Date
    • Thread