示例#1
0
char testNoCallback(float seconds, float frequency)
{
  MMRESULT result;

  HWAVEOUT waveOut;
  result = waveOutOpen(&waveOut,
		       WAVE_MAPPER,
		       &waveFormat,
		       0,
		       0,
		       CALLBACK_NULL);
  if(result != MMSYSERR_NOERROR) {
    printf("waveOutOpen failed (result=%d)\n", result);
    return 1;
  }

  printf("Opened Wave Mapper!\n");
  fflush(stdout);
  
  DWORD sampleCount = seconds * waveFormat.nSamplesPerSec;
  LPSTR block = allocateBlock(sampleCount);
  fillSinWave(block, frequency, sampleCount);
  
  printf("Writing block...\n");
  fflush(stdout);
  writeAudioBlock(waveOut, block, sampleCount * waveFormat.nBlockAlign);

  waveOutClose(waveOut);

  return 0;
}
示例#2
0
 void playAudio()
 {
	writeAudioBlock(hWaveOut, block, blockSize);
 }
/**
    \fn fillAudio
    \brief push audio packets until nextDts is reached
*/  
bool muxerMp4v2::fillAudio(uint64_t targetDts)
{
    for(int audioIndex=0;audioIndex<nbAStreams;audioIndex++)
    {
                ADM_audioStream         *a=aStreams[audioIndex];
                uint32_t                fq=a->getInfo()->frequency;
                mp4v2AudioPacket       *pkt=&(audioPackets[audioIndex]);
                audioClock             *clock=pkt->clock;
                if(pkt->eos)            continue;
                uint64_t                extraSamples=0;
                while(1)
                {
                        int current=!pkt->nextWrite;
                        int other=pkt->nextWrite;
                        mp4v2AudioPacket::mp4v2AudioBlock        *currentBlock=&(pkt->blocks[current]);
                        mp4v2AudioPacket::mp4v2AudioBlock        *otherBlock=&(pkt->blocks[other]);
                        // Get our currentDts
                        uint64_t currentDts=clock->getTimeUs();                        
                        uint64_t blockDts=currentBlock->dts;
                        if(pkt->eos)            break;
                        extraSamples=0;
                        // Take either block Dts or our own if no DTS is provided
                        if(currentBlock->dts!=ADM_NO_PTS)
                        {
                            bprintf("Current audio Dts=%"PRId64"\n",currentDts);
                            bprintf("Incoming block, dts=%"PRId64"\n",currentBlock->dts);
                            bprintf("Delta =%d ms\n",(int)(currentDts-currentBlock->dts));
                            if( labs((long int)currentBlock->dts-(long int)currentDts)>MP4V2_MAX_JITTER)
                            {
                                if(currentBlock->dts<currentDts)
                                    {
                                            ADM_warning("Audio going back in time audio track %d\n",audioIndex);
                                            ADM_warning("expected %d ms, got %d ms",currentDts/1000,currentBlock->dts/1000);
                                            ADM_warning("Dropping packet\n");
                                            goto nextOne;
                                    }
                                // We have a hole, increase duration of current packet
                                double holeDurationUs=currentBlock->dts-currentDts;
                                ADM_warning("Hole detected in audio of %d ms, track %d\n",(int)(holeDurationUs/1000),audioIndex);
                                ADM_warning("we got a timing of %s",ADM_us2plain(currentBlock->dts));
                                ADM_warning("and expected %s\n",ADM_us2plain(currentDts));
                                holeDurationUs*=fq;
                                holeDurationUs/=1000*1000;
                                ADM_warning("Increasing hole duration by %d samples\n",(int)holeDurationUs);
                                extraSamples=(uint64_t)holeDurationUs;
                            }
                        }else       
                            blockDts=currentDts;
                        if(blockDts>targetDts) // In the future
                            break;
                        if(false==writeAudioBlock(audioIndex,currentBlock,currentBlock->nbSamples+extraSamples))
                        {
                            ADM_error("Cannot write audio sample for track %d\n",audioIndex);
                            pkt->eos=true;
                            return false;
                        }
                        // load next

                        clock->advanceBySample(currentBlock->nbSamples+extraSamples);
nextOne:
                        if(false==loadAndToggleAudioSlot(audioIndex))
                        {
                            ADM_warning("End of audio stream %d\n",audioIndex);
                            #warning Purge other slot
                            pkt->eos=true;
                        }
                }
    }
    return true;
}