How to start an audio file from a specific location using AudioQueue?

I analyzed the "SpeakHere" code sample on the iPhone dev forum.

There is code to run AudioQueue as follows:

AudioTimeStamp ats = {0};
AudioQueueStart(mQueue, &ats);

But I do not know how to start the middle part of the file.

I changed AudioTimeStamp with various values, including negative. But that does not work.

Please let me know your wonderful opinion. Thank.

+3
source share
1 answer

AudioQueueStart- This is not a feature to help you do this. Time is there, like a delay, if you pass NULL, it means that the queue will start as soon as possible.

, , , , (), .

, SpeakHere

( obj++) SpeakHere

AQPlayer.h :

UInt64 mPacketCount;

:

void SetQueuePosition(float position) { mCurrentPacket = mPacketCount*position; };

AQPlayer.mm AQPlayer::SetupNewQueue() mIsInitialized = true; :

// get the total number of packets
UInt32 sizeOfPacketsCount = sizeof(mPacketCount);
XThrowIfError (AudioFileGetProperty (mAudioFile, kAudioFilePropertyAudioDataPacketCount, &sizeOfPacketsCount, &mPacketCount), "get packet count");

( SpeakHereControler.mm UISlider, ):

- (IBAction) sliderValueChanged:(UISlider *) sender
{
    float value = [sender value];
    player->SetQueuePosition(position);
}

:

AudioQueueOutputCallback, SpeakHere: void AQPlayer::AQBufferCallback( , , ) AudioFileReadPackets, . mCurrentPacket, , , , , , , , :)


:)

( objc) SpeakHere

AudioPlayer.h :

UInt64      totalFrames;

AudioPlayer.m - (void) openPlaybackFile: (CFURLRef) soundFile :

UInt32 sizeOfTotalFrames = sizeof(UInt64);
AudioFileGetProperty (                        
          [self audioFileID], 
          kAudioFilePropertyAudioDataPacketCount,
          &sizeOfTotalFrames,
          &totalFrames
          );

AudioPlayer.h .m

- (void) setRelativePlaybackPosition: (float) position 
{
    startingPacketNumber = totalFrames * position;
}

( AudioViewController UISlider, ):

- (IBAction) setPlaybackPosition: (UISlider *) sender
{
    float value = [sender value];
    [audioPlayer setRelativePlaybackPosition: value];
}

0, , 0,5 ..


, .

+6

Source: https://habr.com/ru/post/1756411/


All Articles