PVR_ERROR cHTSPData::RequestChannelList(PVRHANDLE handle, int radio) { if (!CheckConnection()) return PVR_ERROR_SERVER_ERROR; SChannels channels = GetChannels(); for(SChannels::iterator it = channels.begin(); it != channels.end(); ++it) { SChannel& channel = it->second; PVR_CHANNEL tag; memset(&tag, 0 , sizeof(tag)); tag.uid = channel.id; tag.number = channel.id; tag.name = channel.name.c_str(); tag.callsign = channel.name.c_str(); tag.radio = channel.radio; tag.encryption = channel.caid; tag.input_format = ""; tag.stream_url = ""; tag.bouquet = 0; if(((bool)radio) == tag.radio) { PVR->TransferChannelEntry(handle, &tag); } } return PVR_ERROR_NO_ERROR; }
/*--------------------------------------------------------------------------------*/ bool ADMRIFFFile::CreateExtraChunks() { bool success = true; if (adm) { RIFFChunk *chunk; uint64_t chnalen; uint8_t *chna; uint_t i, nchannels = GetChannels(); success = true; for (i = 0; i < nchannels; i++) { ADMAudioTrack *track; // create chna track data if ((track = adm->CreateTrack(i)) != NULL) { track->SetSampleRate(GetSampleRate()); track->SetBitDepth(GetBitsPerSample()); } } if (!admfile.empty()) { // create ADM structure (content and objects from file) if (adm->CreateFromFile(admfile.c_str())) { // can prepare cursors now since all objects have been created PrepareCursors(); } else { BBCERROR("Unable to create ADM structure from '%s'", admfile.c_str()); success = false; } } // get ADM object to create chna chunk if ((chna = adm->GetChna(chnalen)) != NULL) { // and add it to the RIFF file if ((chunk = AddChunk(chna_ID)) != NULL) { success &= chunk->CreateChunkData(chna, chnalen); } else BBCERROR("Failed to add chna chunk"); // don't need the raw data any more delete[] chna; } else BBCERROR("No chna data available"); success &= (AddChunk(axml_ID) != NULL); } return success; }
PVR_ERROR CHTSPData::GetChannels(PVR_HANDLE handle, bool bRadio) { SChannels channels = GetChannels(); for(SChannels::iterator it = channels.begin(); it != channels.end(); ++it) { SChannel& channel = it->second; if(bRadio != channel.radio) continue; PVR_CHANNEL tag; memset(&tag, 0 , sizeof(PVR_CHANNEL)); tag.iUniqueId = channel.id; tag.bIsRadio = channel.radio; tag.iChannelNumber = channel.num; tag.strChannelName = channel.name.c_str(); tag.strInputFormat = ""; // unused tag.strStreamURL = ""; // unused tag.iEncryptionSystem = channel.caid; tag.strIconPath = channel.icon.c_str(); tag.bIsHidden = false; PVR->TransferChannelEntry(handle, &tag); } return PVR_ERROR_NO_ERROR; }
PVR_ERROR CHTSPData::GetChannelGroupMembers(PVR_HANDLE handle, const PVR_CHANNEL_GROUP &group) { XBMC->Log(LOG_DEBUG, "%s - group '%s'", __FUNCTION__, group.strGroupName); for(unsigned int iTagPtr = 0; iTagPtr < m_tags.size(); iTagPtr++) { if (m_tags[iTagPtr].name != group.strGroupName) continue; SChannels channels = GetChannels(m_tags[iTagPtr].id); for(SChannels::iterator it = channels.begin(); it != channels.end(); ++it) { SChannel& channel = it->second; PVR_CHANNEL_GROUP_MEMBER tag; memset(&tag,0 , sizeof(PVR_CHANNEL_GROUP_MEMBER)); tag.strGroupName = group.strGroupName; tag.iChannelUniqueId = channel.id; tag.iChannelNumber = channel.num; XBMC->Log(LOG_DEBUG, "%s - add channel %s (%d) to group '%s' channel number %d", __FUNCTION__, channel.name.c_str(), tag.iChannelUniqueId, group.strGroupName, channel.num); PVR->TransferChannelGroupMember(handle, &tag); } } return PVR_ERROR_NO_ERROR; }
uint8_t *GetPixelPtr(CSBitmap* pBitmap, int x, int y) { assert(HasBitmap(pBitmap)); assert(y >= 0 && y < GetHeight(pBitmap)); assert(x >= 0 && x < GetWidth(pBitmap)); return GetLinePtr(pBitmap, y) + x * GetChannels(pBitmap); }
static void RandomDitherBitmap(CSBitmap* pBitmap, int ditherAmount) { const int width = GetWidth(pBitmap); const int height = GetHeight(pBitmap); const int numChannels = GetChannels(pBitmap); if (numChannels < 3) return; for (int y = 0; y < height; ++y) { uint8_t* pPixel = GetLinePtr(pBitmap, y); for (int x = 0; x < width; ++x) { int offset = (rand() % ditherAmount) - (ditherAmount / 2); for (int chan = 0; chan < 3; ++chan) { int Value = pPixel[chan] + offset; if (Value < 0) Value = 0; if (Value > 255) Value = 255; pPixel[chan] = Value; } pPixel += numChannels; } } }
BOOL OSndStreamWAV::OpenStream( const CUString& strFileName ) { SF_INFO wfInfo; memset(&wfInfo,0,sizeof(SF_INFO)); wfInfo.samplerate = GetSampleRate(); wfInfo.frames = -1; wfInfo.sections = 1; wfInfo.channels = GetChannels(); wfInfo.format = (SF_FORMAT_WAV | m_OutputFormat) ; // Set file name SetFileName(strFileName); CUStringConvert strCnv; // Open stream #ifdef _UNICODE if (! (m_pSndFile = sf_open( (const tchar*)strCnv.ToT( GetFileName() + _W( "." ) + GetFileExtention() ), SFM_WRITE, &wfInfo ) ) ) #else if (! (m_pSndFile = sf_open( strCnv.ToT( GetFileName() + _W( "." ) + GetFileExtention() ), SFM_WRITE, &wfInfo ) ) ) #endif { ASSERT( FALSE ); return FALSE; } // return Success return TRUE; }
void SetPalette(CSBitmap* pBitmap, int StartColor, int NumColors, RGBQUAD* pColors) { assert(HasBitmap(pBitmap)); assert(GetChannels(pBitmap) == 1); assert(StartColor >= 0); assert(StartColor + NumColors <= 256); SetDIBColorTable(GetDrawSurface(pBitmap), StartColor, NumColors, pColors); }
int Buffer::GetChannels() const { #ifdef HAS_AUDIO_BUFFER return impl->GetChannels(); #else throw System::PunkException(L"Audio buffer not supported"); #endif }
int AudioFormat_YM::GetPosition() { if (!ymFile_) { return 0; } return (int)((ymFile_->getPos()/1000.0f)*GetChannels()*(GetBitsPerSample()/8)*GetFrequency()); }
PVR_ERROR cHTSPData::GetEpg(PVR_HANDLE handle, const PVR_CHANNEL &channel, time_t iStart, time_t iEnd) { if (!CheckConnection()) return PVR_ERROR_SERVER_ERROR; SChannels channels = GetChannels(); if (channels.find(channel.iUniqueId) != channels.end()) { time_t stop; SEvent event; event.id = channels[channel.iUniqueId].event; if (event.id == 0) return PVR_ERROR_NO_ERROR; do { bool success = GetEvent(event, event.id); if (success) { EPG_TAG broadcast; memset(&broadcast, 0, sizeof(EPG_TAG)); broadcast.iUniqueBroadcastId = event.id; broadcast.strTitle = event.title.c_str(); broadcast.iChannelNumber = event.chan_id >= 0 ? event.chan_id : channel.iUniqueId; broadcast.startTime = event.start; broadcast.endTime = event.stop; broadcast.strPlotOutline = ""; // unused broadcast.strPlot = event.descs.c_str(); broadcast.strIconPath = ""; // unused broadcast.iGenreType = (event.content & 0x0F) << 4; broadcast.iGenreSubType = event.content & 0xF0; broadcast.firstAired = 0; // unused broadcast.iParentalRating = 0; // unused broadcast.iStarRating = 0; // unused broadcast.bNotify = false; broadcast.iSeriesNumber = 0; // unused broadcast.iEpisodeNumber = 0; // unused broadcast.iEpisodePartNumber = 0; // unused broadcast.strEpisodeName = ""; // unused PVR->TransferEpgEntry(handle, &broadcast); event.id = event.next; stop = event.stop; } else break; } while(iEnd > stop); return PVR_ERROR_NO_ERROR; } return PVR_ERROR_NO_ERROR; }
void AudioFormat_YM::SetPosition(int position) { if (!ymFile_) { return; } float sampleSize=(float)(GetChannels()*GetFrequency()*(GetBitsPerSample()/8)); float time=position/sampleSize; ymFile_->setMusicTime((int)(time*1000.0f)); }
void ScaleBitmap(CSBitmap* SourceBitmap, CSBitmap* DestBitmap, bool Filtered) { assert(HasBitmap(SourceBitmap)); assert(HasBitmap(DestBitmap)); if (GetChannels(DestBitmap) >= 3 && Filtered) FilterScaleBitmap(SourceBitmap, DestBitmap); else PointScaleBitmap(SourceBitmap, DestBitmap); }
bool GetPalette(CSBitmap* pBitmap, int StartColor, int NumColors, RGBQUAD* pColors) { assert(HasBitmap(pBitmap)); assert(GetChannels(pBitmap) == 1); assert(StartColor >= 0); assert(StartColor + NumColors <= 256); // Zero the destination array to make sure all bytes get cleared, even if // the function fails. memset(pColors, 0, sizeof(RGBQUAD) * NumColors); int GotCount = GetDIBColorTable(GetDrawSurface(pBitmap), StartColor, NumColors, pColors); return GotCount == NumColors; }
SChannels CHTSPData::GetChannels(int tag) { CMD_LOCK; if(tag == 0) return m_channels; STags::iterator it = m_tags.find(tag); if(it == m_tags.end()) { SChannels channels; return channels; } return GetChannels(it->second); }
void CRingModulationEffect::Process(double * const &frame) { // determine the second waveform double sample = sin(m_phase); // modify the input for (unsigned int i = 0; i < GetChannels(); i++) { frame[i]*= sample; } // increment the phase m_phase+= 2 * M_PI * m_frequency * GetSamplePeriod(); }
PVR_ERROR cHTSPData::RequestEPGForChannel(PVRHANDLE handle, const PVR_CHANNEL &channel, time_t start, time_t end) { if (!CheckConnection()) return PVR_ERROR_SERVER_ERROR; SChannels channels = GetChannels(); if (channels.find(channel.uid) != channels.end()) { time_t stop; SEvent event; event.id = channels[channel.uid].event; if (event.id == 0) return PVR_ERROR_NO_ERROR; do { bool success = GetEvent(event, event.id); if (success) { PVR_PROGINFO broadcast; memset(&broadcast, 0, sizeof(PVR_PROGINFO)); broadcast.channum = event.chan_id >= 0 ? event.chan_id : channel.number; broadcast.uid = event.id; broadcast.title = event.title.c_str(); broadcast.subtitle = event.title.c_str(); broadcast.description = event.descs.c_str(); broadcast.starttime = event.start; broadcast.endtime = event.stop; broadcast.genre_type = (event.content & 0x0F) << 4; broadcast.genre_sub_type = event.content & 0xF0; PVR->TransferEpgEntry(handle, &broadcast); event.id = event.next; stop = event.stop; } else break; } while(end > stop); return PVR_ERROR_NO_ERROR; } return PVR_ERROR_NO_ERROR; }
int CMpegFrame::GetMainDataSize() const { int nSlots = GetFrameSize(); //Header Bytes nSlots -= 4; //CRC Bytes if( m_nProtectionBit==0 ){ nSlots -= 2; } //SideInfo Bytes if( GetChannels()==1 ){ nSlots -= 17; } else{ nSlots -=32; } return nSlots; }
/*--------------------------------------------------------------------------------*/ void ADMRIFFFile::PrepareCursors() { if (adm && writing && !cursors.size()) { std::vector<const ADMAudioObject *> objects; ADMTrackCursor *cursor; uint_t i, nchannels = GetChannels(); // get list of ADMAudioObjects adm->GetAudioObjectList(objects); // add all objects to all cursors for (i = 0; i < nchannels; i++) { // create track cursor for tracking position during writing if ((cursor = new ADMTrackCursor(i)) != NULL) { cursor->Add(objects); cursors.push_back(cursor); } } } }
// Get channels list. void meth::GetChannelsList(LogicalConnections::iterator conn, String user_chnls, String &response) { ChannelsList channels = GetChannels(); bool first_channel = true; response = "["; for (ChannelsList::iterator channel = channels.begin(); channel != channels.end(); channel++) { if (channel->visibility == 1) { // Add comma before each channel except first. if (!first_channel) { response += ","; } else { first_channel = false; } response += "{"; AddPair(response, "name", channel->name, true, true); AddPair(response, "topic", channel->topic, true, true); AddPair(response, "users_online", channel->online_users, false, true); AddPair(response, "access", (int) channel->access, false, false); response += "}"; } } response += "]"; }
BOOL PlayWavStream::OpenStream(const CUString& strFileName) { memset(&m_WavFormat,0,sizeof(m_WavFormat)); m_WavFormat.wBitsPerSample = 16; m_WavFormat.wFormatTag = WAVE_FORMAT_PCM; m_WavFormat.nChannels = GetChannels(); m_WavFormat.nSamplesPerSec = GetSampleRate(); m_WavFormat.nAvgBytesPerSec = (DWORD) m_WavFormat.nChannels * m_WavFormat.nSamplesPerSec * 2; m_WavFormat.nBlockAlign = (WORD) (m_WavFormat.nChannels << 1); m_WavFormat.cbSize = 0; m_mtWavOut.Lock(); m_pWavOut=new CWaveOut(&m_WavFormat,NUMSTREAMBUFFERS,STREAMBUFFERSIZE); m_mtWavOut.Unlock(); if ( NULL == m_pWavOut ) return FALSE; return TRUE; }
bool AlsaSource::SetupHW () { bool result = false; bool rw_available = false; bool mmap_available = false; #if DEBUG bool debug = debug_flags & RUNTIME_DEBUG_AUDIO; #else bool debug = false; #endif snd_pcm_hw_params_t *params = NULL; snd_output_t *output = NULL; guint32 buffer_time = 100000; // request 0.1 seconds of buffer time. int err = 0; int dir = 0; unsigned int rate = GetSampleRate (); unsigned int actual_rate = rate; guint32 channels = GetChannels (); if (debug) { err = snd_output_stdio_attach (&output, stdout, 0); if (err < 0) LOG_AUDIO ("AlsaSource::SetupHW (): Could not create alsa output: %s\n", snd_strerror (err)); } err = snd_pcm_hw_params_malloc (¶ms); if (err < 0) { LOG_AUDIO ("AlsaSource::SetupHW (): Audio HW setup failed (malloc): %s\n", snd_strerror (err)); return false; } // choose all parameters err = snd_pcm_hw_params_any (pcm, params); if (err < 0) { LOG_AUDIO ("AlsaSource::SetupHW (): Audio HW setup failed (no configurations available): %s\n", snd_strerror (err)); goto cleanup; } if (debug && output != NULL) { LOG_AUDIO ("AlsaSource::SetupHW (): hw configurations:\n"); snd_pcm_hw_params_dump (params, output); } // enable software resampling err = snd_pcm_hw_params_set_rate_resample (pcm, params, 1); if (err < 0) { LOG_AUDIO ("AlsaSource::SetupHW (): Audio HW setup failed (could not enable resampling): %s\n", snd_strerror (err)); goto cleanup; } // test for available transfer modes if (!(moonlight_flags & RUNTIME_INIT_AUDIO_ALSA_MMAP)) { err = snd_pcm_hw_params_test_access (pcm, params, SND_PCM_ACCESS_RW_INTERLEAVED); if (err < 0) { LOG_AUDIO ("AlsaSource::SetupHW (): Audio HW setup: RW access mode not supported (%s).\n", snd_strerror (err)); } else { rw_available = true; } } if (!(moonlight_flags & RUNTIME_INIT_AUDIO_ALSA_RW)) { err = snd_pcm_hw_params_test_access (pcm, params, SND_PCM_ACCESS_MMAP_INTERLEAVED); if (err < 0) { LOG_AUDIO ("AlsaSource::SetupHW (): Audio HW setup: MMAP access mode not supported (%s).\n", snd_strerror (err)); } else { mmap_available = true; } } if (mmap_available) { mmap = true; } else if (rw_available) { mmap = false; } else { LOG_AUDIO ("AlsaSource::SetupHW (): Audio HW setup failed, no available access mode\n"); goto cleanup; } LOG_AUDIO ("AlsaSource::SetupHW (): Audio HW setup: using %s access mode.\n", mmap ? "MMAP" : "RW"); // set transfer mode (mmap or rw in our case) err = snd_pcm_hw_params_set_access (pcm, params, mmap ? SND_PCM_ACCESS_MMAP_INTERLEAVED : SND_PCM_ACCESS_RW_INTERLEAVED); if (err < 0) { LOG_AUDIO ("AlsaSource::SetupHW (): Audio HW setup failed (access type not available for playback): %s\n", snd_strerror (err)); goto cleanup; } // set audio format switch (GetInputBytesPerSample ()) { case 1: // 8 bit audio err = snd_pcm_hw_params_set_format (pcm, params, SND_PCM_FORMAT_S16); SetOutputBytesPerSample (2); break; case 2: // 16 bit audio err = snd_pcm_hw_params_set_format (pcm, params, SND_PCM_FORMAT_S16); SetOutputBytesPerSample (2); break; case 3: // 24 bit audio // write as 32 bit audio, this is a lot easier to write to than 24 bit. err = snd_pcm_hw_params_set_format (pcm, params, SND_PCM_FORMAT_S32); SetOutputBytesPerSample (4); break; default: LOG_AUDIO ("AlsaSource::SetupHW (): Invalid input bytes per sample, expected 1, 2 or 3, got %i\n", GetInputBytesPerSample ()); goto cleanup; } if (err < 0) { LOG_AUDIO ("AlsaSource::SetupHW (): Audio HW setup failed (sample format not available for playback): %s\n", snd_strerror (err)); goto cleanup; } // set channel count err = snd_pcm_hw_params_set_channels (pcm, params, channels); if (err < 0) { LOG_AUDIO ("AlsaSource::SetupHW (): Audio HW setup failed (channels count %i not available for playback): %s\n", channels, snd_strerror (err)); goto cleanup; } // set sample rate err = snd_pcm_hw_params_set_rate_near (pcm, params, &actual_rate, 0); if (err < 0) { LOG_AUDIO ("AlsaSource::SetupHW (): Audio HW setup failed (sample rate %i Hz not available for playback): %s\n", rate, snd_strerror (err)); goto cleanup; } else if (actual_rate != rate) { LOG_AUDIO ("AlsaSource::SetupHW (): Audio HW setup failed (sample rate %i Hz not available for playback, only got %i Hz).\n", rate, actual_rate); goto cleanup; } // set the buffer time err = snd_pcm_hw_params_set_buffer_time_near (pcm, params, &buffer_time, &dir); if (err < 0) { LOG_AUDIO ("AudioNode::SetupHW (): Audio HW setup failed (unable to set buffer time %i for playback: %s\n", buffer_time, snd_strerror (err)); goto cleanup; } // write the parameters to device err = snd_pcm_hw_params (pcm, params); if (err < 0) { LOG_AUDIO ("AlsaSource::SetupHW (): Audio HW setup failed (unable to set hw params for playback: %s)\n", snd_strerror (err)); if (debug && output != NULL) { LOG_AUDIO ("AlsaSource::SetupHW (): current hw configurations:\n"); snd_pcm_hw_params_dump (params, output); } goto cleanup; } if (debug) { LOG_AUDIO ("AlsaSource::SetupHW (): hardware pause support: %s\n", snd_pcm_hw_params_can_pause (params) == 0 ? "no" : "yes"); LOG_AUDIO ("AlsaSource::SetupHW (): succeeded\n"); if (output != NULL) snd_pcm_hw_params_dump (params, output); } result = true; cleanup: snd_pcm_hw_params_free (params); return result; }
unsigned int CHTSPData::GetNumChannels() { return GetChannels().size(); }
void hSoundResource::GetBufferInfo( hSoundSourceBufferInfo* outInfo ) { outInfo->channels_ = GetChannels(); outInfo->format_ = GetFormat(); outInfo->pitch_ = (hFloat)GetPitch();//Plays too fast -- not sure why }
/* MATLAB TO C-CALL LINKING FUNCTION */ void mexFunction( int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[] ) { char *Family; int i, FunctionType, NumberOfAverages, ChanTypeFlag, WaitOnSPFlag, status, SleepTimeInt; int nrowsDeviceNum, ncolsDeviceNum; int nrowsSectorNum, ncolsSectorNum; int nrowsNewSP, ncolsNewSP; int nrowst, ncolst; double *AM, *SectorNum, *DeviceNum, *NewSP, *t, *tout, *ErrorFlag, t0=0, SleepTime, Time0; /* Check Inputs */ if (nrhs < 4) mexErrMsgTxt("More input arguments needed (4 to get a channel, 5 to set a channel) (alslink.c)."); /* Input 1: Function type (int, scalar) */ /* 0 -> GetChannels */ /* 1 -> SetChannels */ FunctionType = (int) mxChkGetScalar(INPUT1); /* Input 2: Family name (string) */ Family = mxCalloc(50, sizeof(char)); mxChkGetString(INPUT2, Family); /* Input 3: Sector (column vector) */ nrowsSectorNum = (int) mxGetM(INPUT3); ncolsSectorNum = (int) mxGetN(INPUT3); if (!mxIsNumeric(INPUT3) || mxIsComplex(INPUT3) || !mxIsDouble(INPUT3) || ncolsSectorNum != 1) mexErrMsgTxt("SectorNum must be a column vector equal to DeviceNum."); SectorNum = mxGetPr(INPUT3); /* Input 4: Magnet Numbers (column vector) */ nrowsDeviceNum = (int) mxGetM(INPUT4); ncolsDeviceNum = (int) mxGetN(INPUT4); if (!mxIsNumeric(INPUT4) || mxIsComplex(INPUT4) || !mxIsDouble(INPUT4) || ncolsDeviceNum != 1 || nrowsSectorNum != nrowsDeviceNum) mexErrMsgTxt("DeviceNum must be a column vector equal to SectorNum."); DeviceNum = mxGetPr(INPUT4); if (FunctionType == 0) { /* Get channels */ /* Input 5: NumberOfAverages (int, scalar) */ if (nrhs >= 5) NumberOfAverages = (int) mxChkGetScalar(INPUT5); else NumberOfAverages = 1; /* Input 6: ChanTypeFlag (int, scalar) */ if (nrhs >= 6) ChanTypeFlag = (int) mxChkGetScalar(INPUT6); else ChanTypeFlag = 0; /* Default: AM */ /* Input 7 */ if (nrhs >= 7) { nrowst = (int) mxGetM(INPUT7); ncolst = (int) mxGetN(INPUT7); if (!mxIsNumeric(INPUT7) || mxIsComplex(INPUT7) || !mxIsDouble(INPUT7) || (nrowst != 1)) mexErrMsgTxt("t must be a row vector."); t = mxGetPr(INPUT7); } else { nrowst = 1; ncolst = 1; t = &t0; } /* Create output vectors */ OUTPUT1 = mxCreateDoubleMatrix((unsigned int) nrowsDeviceNum, (unsigned int) ncolst, mxREAL); AM = mxGetPr(OUTPUT1); if (nlhs >= 2) { OUTPUT2 = mxCreateDoubleMatrix((unsigned int) nrowst, (unsigned int) ncolst, mxREAL); tout = mxGetPr(OUTPUT2); } /* Data Loop */ Time0 = GetTime(); for (i=0; i<ncolst; i++) { /* Delay between sample points */ SleepTime = t[i] - (GetTime()-Time0) - .002; if (SleepTime > 0) { SleepTimeInt = (int) (1000 * SleepTime); /* printf(" SleepTime = %f %d\n", SleepTime, SleepTimeInt); */ sca_sleep(SleepTimeInt, 100000); } /* Get outputs */ status = GetChannels(Family, SectorNum, DeviceNum, &(AM[i*nrowsDeviceNum]), nrowsDeviceNum, NumberOfAverages, ChanTypeFlag); if (nlhs >= 2) tout[i] = GetTime() - Time0; } if (nlhs >= 3) { OUTPUT3 = mxCreateDoubleMatrix((unsigned int) 1, (unsigned int) 1, mxREAL); ErrorFlag = mxGetPr(OUTPUT3); *ErrorFlag = (double) status; } } else if (FunctionType == 1) { /* Set channels */ if (nrhs < 5) mexErrMsgTxt("Atleast 5 input arguments needed for setting channels (alslink.c)."); /* Input 5: Magnet Numbers (column vector) */ nrowsNewSP = (int) mxGetM(INPUT5); ncolsNewSP = (int) mxGetN(INPUT5); if (!mxIsNumeric(INPUT5) || mxIsComplex(INPUT5) || !mxIsDouble(INPUT5) || ncolsDeviceNum != 1 || nrowsNewSP != nrowsDeviceNum) mexErrMsgTxt("NewSP must be a column vector equal to SectorNum & DeviceNum."); NewSP = mxGetPr(INPUT5); /* Input 6: ChanTypeFlag (int, scalar) */ if (nrhs >= 6) ChanTypeFlag = (int) mxChkGetScalar(INPUT6); else ChanTypeFlag = 1; /* Default: AC */ /* Input 7: WaitOnSPFlag (int, scalar) */ if (nrhs >= 7) WaitOnSPFlag = (int) mxChkGetScalar(INPUT7); else WaitOnSPFlag = 1; /* Default: wait */ /* Create output vectors */ if (nlhs >= 1) { OUTPUT1 = mxCreateDoubleMatrix((unsigned int) nrowsDeviceNum, (unsigned int) 1, mxREAL); AM = mxGetPr(OUTPUT1); } if (nlhs >= 2) { OUTPUT2 = mxCreateDoubleMatrix((unsigned int) 1, (unsigned int) 1, mxREAL); tout = mxGetPr(OUTPUT2); } /* Data Loop */ Time0 = GetTime(); status = SetChannels(Family, SectorNum, DeviceNum, NewSP, nrowsDeviceNum, ChanTypeFlag, WaitOnSPFlag); if (nlhs >= 3) { OUTPUT3 = mxCreateDoubleMatrix((unsigned int) 1, (unsigned int) 1, mxREAL); ErrorFlag = mxGetPr(OUTPUT3); *ErrorFlag = (double) status; } if (nlhs >= 1) status = GetChannels(Family, SectorNum, DeviceNum, AM, nrowsDeviceNum, 1, 0); if (nlhs >= 2) *tout = GetTime() - Time0; } else mexErrMsgTxt("No function type defined."); mxFree(Family); }
bool AlsaSource::WriteMmap () { snd_pcm_channel_area_t *areas = NULL; snd_pcm_uframes_t offset = 0; snd_pcm_uframes_t frames; snd_pcm_sframes_t available_samples; snd_pcm_sframes_t commitres = 0; guint32 channels = GetChannels (); int err = 0; AudioData *data [channels + 1]; if (GetState () != AudioPlaying) { LOG_ALSA ("AlsaSource::WriteMmap (): trying to write when we're not playing (state: %i)\n", GetState ()); return false; } if (!PreparePcm (&available_samples)) return false; if (GetFlag (AudioEnded)) { Underflowed (); return false; } LOG_ALSA_EX ("AlsaSource::WriteMmap (): entering play loop, avail: %" G_GINT64_FORMAT ", sample size: %i\n", (gint64) available_samples, (int) period_size); frames = available_samples; mutex.Lock (); if (!initialized) goto cleanup; err = snd_pcm_mmap_begin (pcm, (const snd_pcm_channel_area_t** ) &areas, &offset, &frames); if (err < 0) { if (!XrunRecovery (err)) { LOG_AUDIO ("AudioPlayer: could not get mmapped memory: %s\n", snd_strerror (err)); goto cleanup; } started = false; } LOG_ALSA_EX ("AlsaSource::WriteMmap (): can write %lu frames, avail: %lu\n", frames, available_samples); for (guint32 channel = 0; channel < channels; channel++) { data [channel] = (AudioData *) g_malloc (sizeof (AudioData)); // pointer to the first sample to write to data [channel]->dest = ((gint8 *) areas [channel].addr) + (areas [channel].first / 8) + offset * areas [channel].step / 8; // distance (in bytes) between samples data [channel]->distance = areas [channel].step / 8; } data [channels] = NULL; frames = WriteFull (data, frames); for (guint32 channel = 0; channel < channels; channel++) { g_free (data [channel]); } commitres = snd_pcm_mmap_commit (pcm, offset, frames); LOG_ALSA_EX ("AlsaSource::WriteMmap (): played %i samples, of %i available samples, result: %i.\n", (int) frames, (int) 0, (int) commitres); if (commitres < 0 || (snd_pcm_uframes_t) commitres != frames) { if (!XrunRecovery (commitres >= 0 ? -EPIPE : commitres)) { LOG_AUDIO ("AudioPlayer: could not commit mmapped memory: %s\n", snd_strerror(err)); commitres = 0; // so that we end up returning false goto cleanup; } started = false; } cleanup: mutex.Unlock (); return commitres > 0; }
SChannels CHTSPData::GetChannels() { return GetChannels(0); }
//////////////// // Get waveform void AudioProvider::GetWaveForm(int *min,int *peak,__int64 start,int w,int h,int samples,float scale) { // Setup int channels = GetChannels(); int n = w * samples; for (int i=0;i<w;i++) { peak[i] = 0; min[i] = h; } // Prepare waveform int cur; int curvalue; // Prepare buffers int needLen = n*channels*bytes_per_sample; if (raw) { if (raw_len < needLen) { delete raw; raw = NULL; } } if (!raw) { raw_len = needLen; raw = (void*) new char[raw_len]; } if (bytes_per_sample == 1) { // Read raw samples unsigned char *raw_char = (unsigned char*) raw; GetAudio(raw,start,n); int amplitude = h*scale; // Calculate waveform for (int i=0;i<n;i++) { cur = i/samples; curvalue = h - (int(raw_char[i*channels])*amplitude)/0xFF; if (curvalue > h) curvalue = h; if (curvalue < 0) curvalue = 0; if (curvalue < min[cur]) min[cur] = curvalue; if (curvalue > peak[cur]) peak[cur] = curvalue; } } if (bytes_per_sample == 2) { // Read raw samples short *raw_short = (short*) raw; GetAudio(raw,start,n); int half_h = h/2; int half_amplitude = half_h * scale; // Calculate waveform for (int i=0;i<n;i++) { cur = i/samples; curvalue = half_h - (int(raw_short[i*channels])*half_amplitude)/0x8000; if (curvalue > h) curvalue = h; if (curvalue < 0) curvalue = 0; if (curvalue < min[cur]) min[cur] = curvalue; if (curvalue > peak[cur]) peak[cur] = curvalue; } } }
bool ADMRIFFFile::PostReadChunks() { bool success = RIFFFile::PostReadChunks(); // after reading of chunks, find chna and axml chunks and decode them // to create an ADM if (success) { RIFFChunk *chna = GetChunk(chna_ID); RIFFChunk *axml = GetChunk(axml_ID); // ensure each chunk is valid if (adm && chna && chna->GetData() && axml && axml->GetData()) { // decode chunks success = adm->Set(chna->GetData(), chna->GetLength(), (const char *)axml->GetData()); #if BBCDEBUG_LEVEL >= 4 { // dump ADM as text std::string str; adm->Dump(str); BBCDEBUG("%s", str.c_str()); } { // dump ADM as XML std::string str; adm->GetAxml(str); BBCDEBUG("%s", str.c_str()); } BBCDEBUG("Audio objects:"); std::vector<const ADMObject *> list; adm->GetObjects(ADMAudioObject::Type, list); uint_t i; for (i = 0; i < list.size(); i++) { BBCDEBUG("%s", list[i]->ToString().c_str()); } #endif } // test for different types of failure else if (!adm) { BBCERROR("Cannot decode ADM, no ADM decoder available"); success = false; } else if (!chna || !axml) { // acceptable failure - chna and/or axml chunk not specified - not an ADM compatible BWF file but open anyway BBCDEBUG("Warning: no chna/axml chunks!"); // if no chna supplied, create default channel mapping using standard definitions if (adm && !chna) { // attempt to find a single audioPackFormat from the standard definitions with the correct number of channels std::vector<const ADMObject *> packFormats, streamFormats; ADMAudioObject *object = adm->CreateObject("Main"); // create audio object for entire file uint_t i; // get a list of pack formats - these will be searched for the pack format with the correct number of channels adm->GetObjects(ADMAudioPackFormat::Type, packFormats); // get a list of stream formats - these will be used to search for track formats and channel formats adm->GetObjects(ADMAudioStreamFormat::Type, streamFormats); // search all pack formats for (i = 0; i < packFormats.size(); i++) { ADMAudioPackFormat *packFormat; if ((packFormat = dynamic_cast<ADMAudioPackFormat *>(const_cast<ADMObject *>(packFormats[i]))) != NULL) { // get channel format ref list - the size of this dictates the number of channels supported by the pack format const std::vector<ADMAudioChannelFormat *>& channelFormatRefs = packFormat->GetChannelFormatRefs(); // if the pack has the correct number of channels if (channelFormatRefs.size() == GetChannels()) { uint_t j; BBCDEBUG("Found pack format '%s' ('%s') for %u channels", packFormat->GetName().c_str(), packFormat->GetID().c_str(), GetChannels()); // add pack format to audio object if (object) object->Add(packFormat); // for each channel, create a track and link pack format to each for (j = 0; j < channelFormatRefs.size(); j++) { ADMAudioChannelFormat *channelFormat = channelFormatRefs[j]; ADMAudioTrack *track; std::string name; // create track if ((track = adm->CreateTrack(j)) != NULL) { uint_t k; track->Add(packFormat); // find stream format that points to the correct channel format and use that to find the trackFormat for (k = 0; k < streamFormats.size(); k++) { ADMAudioStreamFormat *streamFormat; // stream format points to channel format and track format so look for stream format with the correct channel format ref if (((streamFormat = dynamic_cast<ADMAudioStreamFormat *>(const_cast<ADMObject *>(streamFormats[k]))) != NULL) && streamFormat->GetChannelFormatRefs().size() && (streamFormat->GetChannelFormatRefs()[0] == channelFormat) && // check for correct channel format ref streamFormat->GetTrackFormatRefs().size()) // make sure there are some track formats ref'd as well { // get track format ref ADMAudioTrackFormat *trackFormat = streamFormat->GetTrackFormatRefs()[0]; BBCDEBUG("Found stream format '%s' ('%s') which refs channel format '%s' ('%s')", streamFormat->GetName().c_str(), streamFormat->GetID().c_str(), channelFormat->GetName().c_str(), channelFormat->GetID().c_str()); BBCDEBUG("Found stream format '%s' ('%s') which refs track format '%s' ('%s')", streamFormat->GetName().c_str(), streamFormat->GetID().c_str(), trackFormat->GetName().c_str(), trackFormat->GetID().c_str()); // add track format to track track->Add(trackFormat); break; } } // add track to audio object if (object) object->Add(track); } } break; } } } // set default time limits on audio object if (object && filesamples) { BBCDEBUG("Setting duration to %sns", StringFrom(filesamples->GetLengthNS()).c_str()); object->SetDuration(filesamples->GetLengthNS()); } } success = true; } else { // unacceptible failures: empty chna or empty axml chunks if (chna && !chna->GetData()) BBCERROR("Cannot decode ADM, chna chunk not available"); if (axml && !axml->GetData()) BBCERROR("Cannot decode ADM, axml chunk not available"); success = false; } // now that the data is dealt with, the chunk data can be deleted if (axml) axml->DeleteData(); if (chna) chna->DeleteData(); } return success; }
unsigned ServiceBot::GetChannelCount() const { return GetChannels().size(); }