void SoundcardDialog::checkSupport() { // check if the selected device can do what we want PaSampleFormat sampleFormat = paFloat32; PaStreamParameters inputParams; PaStreamParameters outputParams; memset(&inputParams, 0, sizeof(inputParams)); inputParams.device = getInputSource(); inputParams.suggestedLatency = 0.2f; inputParams.channelCount = 2; inputParams.sampleFormat = sampleFormat; memset(&outputParams, 0, sizeof(outputParams)); outputParams.device = getOutputSource(); outputParams.suggestedLatency = 0.2f; outputParams.channelCount = 2; outputParams.sampleFormat = sampleFormat; PaError err = Pa_IsFormatSupported(&inputParams, &outputParams, getSamplerate()); if (err==paFormatIsSupported) { ui->warningText->setText(""); } else { ui->warningText->setText("Format NOT supported"); } }
void Track::writeData( QByteArray& data) const { QBuffer buffer( data); buffer.open(IO_WriteOnly); QDataStream stream( &buffer); stream.setByteOrder( QDataStream::LittleEndian); /** Write the track header **/ stream << (Q_UINT32) 0x7469686D; // 0x00 mhit stream << (Q_UINT32) 0xf4; // 0x04 headerlen stream << (Q_UINT32) 0x0; // 0x08 length - set later stream << (Q_UINT32) 0x0; // 0x0C number of mhods stream << (Q_UINT32) getID(); // 0x10 stream << (Q_UINT32) 1; // 0x14 //stream << (Q_UINT32) 0; // 0x18 stream << (Q_UINT32) 0x4d503320; // ipod shiffle wants a "MP3 " here stream << vbr; // 0x1C stream << type; // 0x1D stream << compilation; // 0x1E stream << rating; // 0x1F stream << (Q_UINT32) getLastModified()+ MAC_EPOCH_DELTA; // 0x20 stream << (Q_UINT32) getFileSize(); // 0x24 stream << (Q_UINT32) getTrackLength(); // 0x28 stream << (Q_UINT32) getTrackNumber(); // 0x2C stream << (Q_UINT32) getTrackCount(); // 0x30 stream << (Q_UINT32) getYear(); // 0x34 stream << (Q_UINT32) getBitrate(); // 0x38 stream << (Q_UINT32) getSamplerate(); // 0x3C stream << (Q_UINT32) getVolumeAdjust(); // 0x40 stream << (Q_UINT32) 0; // 0x44 empty space //stream << (Q_UINT32) getTrackLength(); // 0x48 empty space stream << (Q_UINT32) 0; // 0x48 empty space stream << (Q_UINT32) 0; // 0x4C empty space stream << (Q_UINT32) getPlayCount(); // 0x50 stream << (Q_UINT32) getPlayCount(); // 0x54 stream << (Q_UINT32) getLastPlayed(); // 0x58 stream << (Q_UINT32) getCdNumber(); // 0x5C stream << (Q_UINT32) getCdCount(); // 0x60 stream << (Q_UINT32) 0; // 0x64 empty space //userid from apple store stream << (Q_UINT32) date_added; // 0x68 stream << (Q_UINT32) 0; // boockmarktime stream << (Q_UINT64) dbid; // unique bit (64 bit) stream << (Q_UINT8) 0; // checked in iTZnes stream << (Q_UINT8) 0; // application rating stream << (Q_UINT16) 0; // BPM stream << (Q_UINT16) 0; // artworkcount stream << (Q_UINT16) 0xffff; // unkown stream << (Q_UINT32) 0; // artwork size stream << (Q_UINT32) 0; // unkown stream << (float) -getSamplerate(); // samplerate as floating point "-"?!? stream << (Q_UINT32) 0; // date/time added stream << (Q_UINT32) file_format_code; // unkown, but 0x0000000c for MP3 ? stream << (Q_UINT32) 0; // unkown stream << (Q_UINT32) 0; // unkown stream << (Q_UINT32) 0; // unkown stream << (Q_UINT32) 0; // unkown stream << (Q_UINT32) 0x02; // unknown stream << (Q_UINT64) dbid; // same unique id as above for( int i= 0; i< 17; i++) stream << (Q_UINT32) 0; /** Write Track contents **/ Q_UINT32 num_mhods = 0; for( PropertyMap::const_iterator element= properties.begin(); element!= properties.end(); ++element) { if( (*element).isEmpty()) continue; const char *data= (const char *)(*element).ucs2(); if( data == NULL) continue; int datalen= 2* (*element).length(); stream << (Q_UINT32) 0x646F686D; // mhod stream << (Q_UINT32) 0x18; // headerlen stream << (Q_UINT32) 40+ datalen; stream << (Q_UINT32) element.key(); stream << (Q_UINT32) 0; stream << (Q_UINT32) 0; stream << (Q_UINT32) 1; // dummy - would refer to the trackID if used in playlist stream << (Q_UINT32) datalen; stream << (Q_UINT32) 0; stream << (Q_UINT32) 0; stream.writeRawBytes( data, datalen); num_mhods++; } buffer.at( 8); stream << (Q_UINT32)data.size(); // set content length stream << (Q_UINT32)num_mhods; // set real mhod count buffer.close(); }
/*! Get sample frames \param buf pointer array to channel buffers \param frames number of maximum frames to get \return frames put into buffers */ int Stream::doGet(int ch,float *const *buf,int frames,float sr) { ASSERT(ch > 0 && frames >= 0 && sr > 0); if(isOk() && !isInitializing()) { // signal thread worker pthread_cond_signal(&cond); // check/(re)allocate buffers int strch = getChannels(); if(bufs && bufch < strch) { delete[] decoded; for(int i = 0; i < bufch; ++i) src_delete(src_state[i]); delete[] src_state; delete[] bufs; bufs = NULL; } if(!bufs) { if(bufch < strch) bufch = strch; bufs = new float *[bufch]; decoded = new Fifo<float>[bufch]; src_state = new SRC_STATE *[bufch]; for(int i = 0; i < bufch; ++i) { int error; src_state[i] = src_new(SRC_ZERO_ORDER_HOLD,1,&error); if(!src_state[i]) post("src init error %i",error); } } // get frames float ratio = sr/getSamplerate(); int frneed = (int)(frames/ratio)+DECMORE; // number of frames to read from decoder fifo if(decoded[0].Size() < frneed) { // fifos are too small -> resize them (while keeping their contents) for(int i = 0; i < bufch; ++i) decoded[i].Resize(frneed,true); } // how many frames do we need to get from decoder? int frread = frneed-decoded[0].Have(); int ret = state == ST_WAIT?0:DataRead(frread); if(ret < 0) { if(debug) post("read error"); // clear output for(int c = 0; c < ch; ++c) memset(buf[c],0,frames*sizeof *buf[c]); return 0; } else { // how many channels do we really need for output? // this should be set elsewhere, because we can't change anyway!!! // (SRC_STATE for dangling channels would be incorrect) int cmin = strch; if(ch < cmin) cmin = ch; // write data to fifo for(int i = 0; i < cmin; ++i) { int wr = decoded[i].Write(ret,bufs[i]); if(wr < ret) post("fifo overflow"); } // state = ST_PROCESS; if(ratio == 1) { // no resampling necessary // hopefully all channel fifos advance uniformly..... for(int i = 0; i < cmin; ++i) { for(int got = 0; got < frames; ) { int cnt = frames-got; if(decoded[i].Have()) { got += decoded[i].Read(cnt,buf[i]+got); } else { state = ST_WAIT; if(debug) post("fifo underrun"); // Buffer underrun!! -> zero output buffer memset(buf[i]+got,0,cnt*sizeof(*buf[i])); got += cnt; } } } } else { SRC_DATA src_data; src_data.src_ratio = ratio; src_data.end_of_input = 0; // hopefully all channel fifos advance uniformly..... for(int i = 0; i < cmin; ++i) { src_set_ratio(src_state[i],ratio); for(int got = 0; got < frames; ) { src_data.data_out = buf[i]+got; src_data.output_frames = frames-got; if(decoded[i].Have()) { src_data.data_in = decoded[i].ReadPtr(); src_data.input_frames = decoded[i].ReadSamples(); int err = src_process(src_state[i],&src_data); if(err) post("src_process error %i",err); // advance buffer decoded[i].Read(src_data.input_frames_used,NULL); } else { state = ST_WAIT; if(debug) post("fifo underrun"); // Buffer underrun!! -> zero output buffer memset(src_data.data_out,0,src_data.output_frames*sizeof(*src_data.data_out)); src_data.output_frames_gen = src_data.output_frames; } got += src_data.output_frames_gen; } } } // zero remaining channels for(int c = cmin; c < ch; ++c) memset(buf[c],0,frames*sizeof *buf[c]); return ret; } } else { for(int c = 0; c < ch; ++c) memset(buf[c],0,frames*sizeof *buf[c]); return 0; } }