Beispiel #1
0
void PuReader::readNextPu()
{
  clearSamples();
  readHeader();
  initSamples();
  readSamples();
}
bool AudioFormatReader::read (int** destSamples,
                              int numDestChannels,
                              int64 startSampleInSource,
                              int numSamplesToRead,
                              const bool fillLeftoverChannelsWithCopies)
{
    jassert (numDestChannels > 0); // you have to actually give this some channels to work with!

    int startOffsetInDestBuffer = 0;

    if (startSampleInSource < 0)
    {
        const int silence = (int) jmin (-startSampleInSource, (int64) numSamplesToRead);

        for (int i = numDestChannels; --i >= 0;)
            if (destSamples[i] != 0)
                zeromem (destSamples[i], sizeof (int) * silence);

        startOffsetInDestBuffer += silence;
        numSamplesToRead -= silence;
        startSampleInSource = 0;
    }

    if (numSamplesToRead <= 0)
        return true;

    if (! readSamples (destSamples, jmin ((int) numChannels, numDestChannels), startOffsetInDestBuffer,
                       startSampleInSource, numSamplesToRead))
        return false;

    if (numDestChannels > (int) numChannels)
    {
        if (fillLeftoverChannelsWithCopies)
        {
            int* lastFullChannel = destSamples[0];

            for (int i = numDestChannels; --i > 0;)
            {
                if (destSamples[i] != 0)
                {
                    lastFullChannel = destSamples[i];
                    break;
                }
            }

            if (lastFullChannel != 0)
                for (int i = numChannels; i < numDestChannels; ++i)
                    if (destSamples[i] != 0)
                        memcpy (destSamples[i], lastFullChannel, sizeof (int) * numSamplesToRead);
        }
        else
        {
            for (int i = numChannels; i < numDestChannels; ++i)
                if (destSamples[i] != 0)
                    zeromem (destSamples[i], sizeof (int) * numSamplesToRead);
        }
    }

    return true;
}
Beispiel #3
0
void CuReconReader::readNextCu()
{
  PuReader puRead(this, sourceFile);
  while (!cu->isCuCompleted())
  {
    puRead.readNextPu();
    readSamples(puRead);
    cu->addPu(*(puRead.getPu()));
  } 
}
void AudioMixer::_musicCallback(void *udata, uint8_t *stream, uint32_t len)
{
    if (_paused) return;

    auto pacm = (libfalltergeist::AcmFileType*)(udata);
    if (pacm->samplesLeft() <= 0)
    {
        if (_loop)
        {
            pacm->rewind();
        }
        else
        {
            Mix_HookMusic(NULL,NULL);
            return;
        }
    }


    if (pacm->filename().find("music") != std::string::npos)
    {
        // music is stereo. just fetch
        pacm->readSamples((short int*)stream, len/2);
    }
    else
    {
        //all other files are mono. double it
        uint16_t* tmp = new uint16_t[len/2];
        uint16_t* sstr = (uint16_t*)stream;
        pacm->readSamples((short int*)tmp, len/4);
        for (uint32_t i = 0; i < len/4; i++)
        {
            sstr[i*2] = tmp[i];
            sstr[i*2+1] = tmp[i];
        }
        delete [] tmp;
    }
}
Beispiel #5
0
long CoreAudioEncoder::inputDataProc(UInt32 *npackets, AudioBufferList *abl)
{
    prepareInputBuffer(abl, *npackets);
    AudioBuffer &ab = abl->mBuffers[0];
    try {
        *npackets = readSamples(ab.mData, *npackets);
    } catch (...) {
        /* treat as EOF */
        *npackets = 0;
    }
    ab.mDataByteSize = *npackets * m_input_desc.mBytesPerFrame;
    if (*npackets == 0)
        ab.mData = 0;
    return 0;
}
Beispiel #6
0
size_t CompositeSource::readSamples(void *buffer, size_t nsamples)
{
    if (m_cur_file == m_sources.size())
        return 0;
    size_t rc = m_sources[m_cur_file]->readSamples(buffer, nsamples);
    if (rc > 0) {
        m_position += rc;
        return rc;
    } else {
        ++m_cur_file;
        if (m_cur_file < m_sources.size())
            m_sources[m_cur_file]->seekTo(0);
        return readSamples(buffer, nsamples);
    }
}
Beispiel #7
0
/*
 Description: read IQ samples from a given WARP node and store them in a given array

 Arguments:
	samples (double my_complex*) 		- pointer to sample array
	start_sample (int)				- offset to the first sample to read
	num_samples (int)				- number of samples to read (between 1 and 2^15)
	node_sock (int)					- identifier of the node socket
	node_id (int)					- identifier of the node
	buffer_id (int)					- identifier of the buffer
	host_id (int)					- identifier of the host
*/
void readIQ(double my_complex* samples, int start_sample, int num_samples, int node_sock, int node_id, int buffer_id, int host_id){

	assert(initialized==1);

	int node_port = 9000 + node_id; // source port at host for node
	int max_length =  8938;//1438, 8938 1422, 8928; // number of bytes available for IQ samples after all headers
	int num_pkts = (int)(num_samples*4/max_length) + 1 ;

	char readIQ_buffer[42] =  {0, 0, 0, node_id, 0, host_id, 0, 1, 0, 28, 0, 10, 0, 0, 48, 0, 0, 8, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};

	char base_ip_addr[20];
	char str[15];
	sprintf(str, "%d", node_id+1);

	strcpy(base_ip_addr, "10.0.0.");
	strcat(base_ip_addr, str);

	readSamples(samples, node_sock, readIQ_buffer , 42, base_ip_addr, node_port, num_samples, (uint32) buffer_id, start_sample, max_length, num_pkts);
}
void AudioMixer::playACMSound(std::string filename)
{
    auto acm = ResourceManager::acmFileType(filename);
    if (!acm) return;
    Logger::debug("AudioMixer") << "playing: " << acm->filename() << std::endl;
    Mix_Chunk *chunk = NULL;

    auto it = _sfx.find(acm->filename());
    if (it != _sfx.end())
    {
        chunk=it->second;
    }

    if (!chunk)
    {
        acm->init();
        auto samples = acm->samples();

        uint8_t *memory = new uint8_t [samples * 2];
        auto cnt = acm->readSamples((short*)memory, samples)*2;

        SDL_AudioCVT cvt;
        SDL_BuildAudioCVT(&cvt, AUDIO_S16LSB, 1, 22050, AUDIO_S16LSB, 2, 22050); //convert from mono to stereo

        cvt.buf = (Uint8*)malloc(cnt*cvt.len_mult);
        memcpy(cvt.buf, (uint8_t*)memory, cnt);
        cvt.len = cnt;
        SDL_ConvertAudio(&cvt);
        // free old buffer
        delete [] memory;

        // make SDL_mixer chunk
        chunk = Mix_QuickLoad_RAW(cvt.buf, cvt.len*cvt.len_ratio);
        if (_sfx.size() > 100) // TODO: make this configurable
        {
            Mix_FreeChunk(_sfx.begin()->second);
            _sfx.erase(_sfx.begin());
        }
        _sfx.insert(std::pair<std::string, Mix_Chunk*>(acm->filename(), chunk));
    }
    Mix_PlayChannel(-1, chunk, 0);
}
Beispiel #9
0
void ExtAFSource::seekTo(int64_t count)
{
    int npreroll = 0;
    
    switch (m_iasbd.mFormatID) {
    case kAudioFormatMPEGLayer1: npreroll = 1; break;
    case kAudioFormatMPEGLayer2: npreroll = 1; break;
    case kAudioFormatMPEGLayer3: npreroll = 10; break;
    }
    int64_t off
        = std::max(0LL, count - m_iasbd.mFramesPerPacket * npreroll);
    CHECKCA(ExtAudioFileSeek(m_eaf, off));
    int32_t distance = count - off;
    while (distance > 0) {
        size_t nbytes = distance * m_asbd.mBytesPerFrame;
        if (nbytes > m_buffer.size())
            m_buffer.resize(nbytes);
        size_t n = readSamples(&m_buffer[0], distance);
        if (n <= 0) break;
        distance -= n;
    }
}