void HotCrossBuns () { Score* score; Tempo* tempo; Musician* musician; MusicSequence* music; SampleDefinition* sample; WavFile* file; WavStream* stream; int sampleVal, i; char* location = "./"; double frequency; score = BuildTestScore (); sample = BuildTestSampleDefinition (); tempo = score->Tempo; musician = BuildTestMusician (sample); music = musician->Play (musician, score); file = BuildTestFile (music, sample); stream = file->ToWavStream (file); file->WriteToFile (file, stream, location); DestroyScore (score); DestroyWavFile (file); DestroyMusician (musician); DestroyWavStream (stream); }
void SpiralLoopPlugin::SaveWav(const char *Filename) { WavFile wav; if (wav.Open(Filename, WavFile::WRITE, WavFile::MONO)) { wav.Save(m_StoreBuffer); } m_Sample=Filename; }
void SpiralLoopPlugin::LoadWav(const char *Filename) { WavFile wav; if (wav.Open(Filename, WavFile::READ)) { //Clear(); AllocateMem(wav.GetSize()); wav.Load(m_StoreBuffer); } }
int FTSound::getNumberOfChannels(const QString &filePath){ WavFile* pfile = new WavFile(NULL); if(!pfile->open(filePath)) return 0; int nchan = pfile->fileFormat().channelCount(); delete pfile; return nchan; }
void setup() { unsigned long now = millis(); while (millis()-now < 2000); BeatDetection::getInstance().setup(); wavfile.readFileHeader("SlimShady.wav"); elapsedTime = 0; BeatDetection& audio = BeatDetection::getInstance(); audio.setSampleRate(wavfile.getSampleRate()); start = 0; loopCounter = 0; elapsedTimeRead_ms = 0; }
void RingtoneTest::testLoadWavefile() { WavFile *wav = new WavFile(); // Test initial values CPPUNIT_ASSERT (wav->isStarted() == false); CPPUNIT_ASSERT (wav->getSize() == 0); // Test protection against wrong file name CPPUNIT_ASSERT (wav->loadFile (std::string ("wrongfilename.wav"), NULL, 44100) == false); delete wav; wav = NULL; }
quint32 QSWindow::onsetDetect(const WavFile &wavFile, const QString &fileName){ QFile od (fileName); od.open(QFile::WriteOnly); QVector<quint8>pitch; QVector<qreal>onset; quint32 len = onsetDetect(wavFile, pitch, onset); quint8 step = wavFile.nChannels(); quint32 winsize = 6000; quint32 winnum = wavFile.length/step/winsize; for(quint32 i=0;i<winnum;++i){ //Spectrum spect(wavFile.data+i*winsize, winsize, 3, step); } QDataStream dt(&od); //TODO: write file: for(quint32 i=0;i<len;++i){ dt<<pitch.at(i)<<onset.at(i)<<'\n'; } od.close(); return len; }
void QSWindow::scoreToWav(){ ui->tabWidget->setCurrentWidget(ui->scoreTab); QSScene* sc = (QSScene*)scoreView->scene(); if(sc==0 || ! QFileInfo(sc->Name()).isFile()){ ui->statusBar->showMessage(QString("No current score file!")); return; } saveFile(); if(saveFileName.isEmpty()){ return; }else{ WavFile wavOut; if(wavOut.fromScore(60.0/80, sc->Name().toStdString().c_str())); wavOut.save(saveFileName.toStdString().c_str()); statusBar()->showMessage(QString("Score to Wave file successful!")); openFileName = saveFileName; QTimer::singleShot(3000, this, SLOT(addScene())); playButton->setEnabled(true); } }
void Sample::loadFromFile(string path) { if(data!=NULL) delete [] data; WavFile wf; if(wf.load((char*)ofToDataPath(path, true).c_str())) { length = wf.getNumFrames(); if(wf.channels==1) { // straight copy data = wf.getData(); } else { // copy only the first channel float *d = wf.getData(); data = new float[length]; for(int i = 0; i < length; i++) { data[i] = d[i*wf.channels]; } delete [] d; } printf("Loaded audio file %d samples\n", wf.getNumFrames()); } else { } }
bool AudioEngine::loadFile(const QString &fileName) { WavFile* sound = new WavFile(); if (!sound->open(fileName)) { // TODO: Deal with failing to load Audio File return false; } _currentSprite->addSound(sound); /*QPixmap waveForm(1000, 1000); waveForm.fill(); QPainter painter; QPen black(Qt::black, 1); painter.begin(&waveForm); painter.setPen(black); short* base = (short*) sound->getDataPointer(); for(int i = 0; i < sound->getDataSize()/2; i++) { float value = base[i] * 500 / 32768; painter.drawLine(i, 500, i, 500+value); } QLabel* label = new QLabel(0, Qt::Window); label->setPixmap(waveForm); label->show(); QAudioFormat format; format.setSampleRate(sound->_wavHeader._samplesPerSec); format.setChannelCount(sound->_wavHeader._numOfChan); format.setSampleSize(sound->_wavHeader._bitsPerSample); format.setCodec("audio/pcm"); format.setByteOrder(QAudioFormat::LittleEndian); format.setSampleType(QAudioFormat::SignedInt); QAudioOutput* audio = new QAudioOutput(format); QBuffer buffer(sound->_dataBuffer); audio->start(&buffer);*/ return true; }
void FTSound::load(int channelid){ if(channelid>1) throw QString("built-in WAV file reader: Can read only the first and unique channel of the file."); m_fileaudioformat = QAudioFormat(); // Clear the format // Create the file reader and read the format WavFile* pfile = new WavFile(this); if(!pfile->open(fileFullPath)) throw QString("built-in WAV file reader: Cannot open the file."); m_fileaudioformat = pfile->fileFormat(); // Check if the format is currently supported if(!m_fileaudioformat.isValid()) throw QString("built-in WAV file reader: Format is invalid."); if(m_fileaudioformat.channelCount()>1) throw QString("built-in WAV file reader: This audio file has multiple audio channel, whereas the built-in reader can read files with only a single channel. Please convert this file into a mono audio file before re-opening it."); if(!((m_fileaudioformat.codec() == "audio/pcm") && m_fileaudioformat.sampleType() == QAudioFormat::SignedInt && m_fileaudioformat.sampleSize() == 16 && m_fileaudioformat.byteOrder() == QAudioFormat::LittleEndian)) throw QString("built-in WAV file reader: Supports only 16 bit signed LE mono format, whereas current format is "+formatToString(m_fileaudioformat)); setSamplingRate(m_fileaudioformat.sampleRate()); // Load the waveform data from the file pfile->seek(pfile->headerLength()); QByteArray buffer; qint64 toread = m_fileaudioformat.sampleSize()/8; qint64 red; buffer.resize(toread); while((red = pfile->read(buffer.data(),toread))) { if(red<toread) throw QString("built-in WAV file reader: The data are corrupted"); // Decode the data for 16 bit signed LE mono format const qint16 value = *reinterpret_cast<const qint16*>(buffer.constData()); wav.push_back(value/32767.0); } delete pfile; }
void loop() { BeatDetection& audio = BeatDetection::getInstance(); static TimePassedBy processAudioTimer; if (start == 0) { elapsedTimeRead_ms = 0; start = millis(); } unsigned long now = millis(); unsigned long elapsedTime = now-start; if (elapsedTime> elapsedTimeRead_ms) { loopCounter++; unsigned long now = millis(); elapsedTime = now-start; uint16_t soundBufferSize = SOUNDBUFFERSIZE; elapsedTimeRead_ms = wavfile.fetchSoundSamples (soundBuffer, soundBufferSize); if (soundBufferSize > 0) { int timediff = (int)elapsedTimeRead_ms - (int)elapsedTime; cout << "t=" << elapsedTime << "ms " << timediff << "ms " << " lc=" << loopCounter << " " << soundBufferSize << " "; bool beatFound = audio.audioReceived(soundBuffer,soundBufferSize); int beatCycle_ms = audio.getBeatCycle_ms(); int bpm = 0; if (beatCycle_ms != 0) bpm = 60UL*4*1000UL/beatCycle_ms; if (beatFound) cout << "*(" << bpm << ")" << endl; else cout << "?(" << bpm << ")" << endl; } } else { usleep(1000); } }
//////////////////////////////////////////////// /// @brief constructor of QS mainwindow /// /// /// /// @author wyj /////////////////////////////////////////////// QSWindow::QSWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::QSWindow), openFileName(""), saveFileName(""), tempFileName(""), mediaPlayer(0), musicthread(0), recorder(new QSRecorder(this)), preset(QSPreset::getInstance(this)) { //qDebug()<<QSettings(QSAbout::domainName, QSAbout::appName).scope(); //QSettings(QSAbout::domainName, QSAbout::appName).clear();//remove this line in release version ui->setupUi(this); preset->readSettings();//ALSO construct ALL Views!! //set icon QIcon iconQS(":/image/QScore.jpg"); setWindowIcon(iconQS); //initialize ui->statusBar->showMessage(QString("Welcome to QtScoreur! ")+QDir::currentPath()); //setAutoFillBackground(false); QPalette winPalette; winPalette.setBrush(QPalette::Window, QBrush(QPixmap(QString(":/image/glry.jpg"), "JPG").scaled(900,600))); //setPalette(winPalette); //music play musicInit(); musicthread = new QSPlayer(openFileName); //// mediaPlayer = musicthread->player; musicthread->start(); preload();//holding all connections needed // load sample score from qrc QString sampleScore = QDir::homePath()+QString("/QS_tmp/thu_anthem_short"); QDir::home().mkdir(QString("QS_tmp")); QFile fw(sampleScore+QString(".txt")), fd(":/sample/thu_anthem_short.txt"); fw.open(QFile::WriteOnly); fd.open(QFile::ReadOnly); QByteArray ba = fd.readAll(); fw.write(ba.constData(),ba.size()); fd.close(); fw.close(); addScene(staffView); addScene(scoreView, sampleScore+QString(".txt")); if(! QFileInfo(sampleScore+QString(".wav")).isFile()){ WavFile wavOut; qDebug()<<"THERE"; if(wavOut.fromScore(60.0/80, (sampleScore+QString(".txt")).toStdString().c_str())){ qDebug()<<"HERE"; wavOut.save(sampleScore.toStdString().append(".wav").c_str()); addScene(wavView, wavOut, sampleScore+QString(".wav")); playButton->setEnabled(true); } }else{ addScene(wavView, sampleScore+QString(".wav")); playButton->setEnabled(true); } keyScene = new KeyScene(keyView, this); //add webView webView = new Html5ApplicationViewer(ui->webTab); webView->setOrientation(Html5ApplicationViewer::ScreenOrientationAuto); webView->resize(900, 400); webView->showExpanded(); webView->loadUrl(QUrl(QLatin1String("http://www.scoreur.net"))); }