void Compiler::generateSourceFiles(const Project& project) { ofDirectory src(project.getPath() + "/src"); src.remove(true); src.create(true); Json::Value projectData = project.getData(); std::string projectFile = _projectFileTemplate; ofStringReplace(projectFile, "<projectfile>", projectData["projectFile"]["fileContents"].asString()); ofStringReplace(projectFile, "<projectname>", projectData["projectFile"]["name"].asString()); _replaceIncludes(projectFile); ofBuffer sourceBuffer(projectFile); ofBufferToFile(src.getAbsolutePath() + "/main.cpp", sourceBuffer); if (project.hasClasses()) { for (unsigned int i = 0; i < projectData["classes"].size(); ++i) { Json::Value c = projectData["classes"][i]; std::string classFile = _classTemplate; ofStringReplace(classFile, "<classname>", c["name"].asString()); ofStringReplace(classFile, "<classfile>", c["fileContents"].asString()); _replaceIncludes(classFile); ofBuffer sourceBuffer(classFile); ofBufferToFile(src.getAbsolutePath() + "/" + c["name"].asString() + ".h", sourceBuffer); } } }
void Upsampler::test() { // // Make some audio data // int sampleRate = 48000; FrequencySweepAudioSource generator; AudioSampleBuffer sourceBuffer(1, sampleRate * 2); AudioSourceChannelInfo asi(&sourceBuffer, 0, sourceBuffer.getNumSamples()); generator.prepareToPlay(sourceBuffer.getNumSamples(), sampleRate); generator.getNextAudioBlock(asi); generator.releaseResources(); // // Create the upsampler // int const upsampleFactor = 4; Upsampler upsampler(sampleRate, sampleRate * upsampleFactor, 2.0); HeapBlock<double> upsamplerInputBuffer, upsamplerOutputBuffer; int upsamplerOutputBufferSamples = sourceBuffer.getNumSamples() * upsampleFactor * 2; upsamplerInputBuffer.allocate(sourceBuffer.getNumSamples(), true); upsamplerOutputBuffer.allocate(upsamplerOutputBufferSamples, true); // // Convert data to doubles // const float* source = sourceBuffer.getReadPointer(0); for (int i = 0; i < sourceBuffer.getNumSamples(); ++i) { upsamplerInputBuffer[i] = source[i]; } // // Upsample // int upsampledCount = upsampler.upsample( upsamplerInputBuffer, upsamplerOutputBuffer, sourceBuffer.getNumSamples(), upsamplerOutputBufferSamples); // // Convert upsampled data to float // AudioSampleBuffer finalBuffer(1, upsamplerOutputBufferSamples); float *destination = finalBuffer.getWritePointer(0); for (int i = 0; i < upsampledCount; ++i) { destination[i] = (float)upsamplerOutputBuffer[i]; } WriteWaveFile("upsample.wav", sampleRate * upsampleFactor, &finalBuffer, upsamplerOutputBufferSamples); }
PassRefPtr<SourceBuffer> SourceBuffer::create(PassOwnPtr<SourceBufferPrivate> sourceBufferPrivate, MediaSource* source, GenericEventQueue* asyncEventQueue) { RefPtr<SourceBuffer> sourceBuffer(adoptRef(new SourceBuffer(sourceBufferPrivate, source, asyncEventQueue))); sourceBuffer->suspendIfNeeded(); return sourceBuffer.release(); }
bool wxLuaSocketBase::WriteDebugData(const wxLuaDebugData& debugData) { // Debug data is written as // [wxInt32 debug data item count] then for each item // [wxInt32 item data length] // [{wxInt32 GetReference}{wxInt32 GetIndex}{wxInt32 GetFlag} // {char GetName \0}{char GetType \0}{char GetValue \0}{char GetSource \0}] wxInt32 idx, idxMax = debugData.GetCount(); wxLuaSocketDebugMsg(m_name + wxT(" wxLuaSocketBase::WriteDebugData"), wxString::Format(wxT("items %d"), idxMax)); bool ok = Write((const char*)&idxMax, sizeof(wxInt32)) == sizeof(wxInt32); for (idx = 0; ok && (idx < idxMax); ++idx) { const wxLuaDebugItem *item = debugData.Item(idx); wxLuaCharBuffer keyBuffer(item->GetKey()); wxLuaCharBuffer valueBuffer(item->GetValue()); wxLuaCharBuffer sourceBuffer(item->GetSource()); int keyLength = keyBuffer.Length() + 1; // add 1 for terminating \0 int valueLength = valueBuffer.Length() + 1; int sourceLength = sourceBuffer.Length() + 1; wxInt32 bufferLength = (5 * sizeof(wxInt32)) + keyLength + valueLength + sourceLength; unsigned char *pBuffer = new unsigned char[bufferLength]; unsigned char *pMemory = pBuffer; ok = Write((const char*)&bufferLength, sizeof(wxInt32)) == sizeof(wxInt32); if (!ok) break; *(wxInt32 *) pMemory = (wxInt32)item->GetRef(); pMemory += sizeof(wxInt32); *(wxInt32 *) pMemory = (wxInt32)item->GetIndex(); pMemory += sizeof(wxInt32); *(wxInt32 *) pMemory = (wxInt32)item->GetFlag(); pMemory += sizeof(wxInt32); *(wxInt32 *) pMemory = (wxInt32)item->GetKeyType(); pMemory += sizeof(wxInt32); *(wxInt32 *) pMemory = (wxInt32)item->GetValueType(); pMemory += sizeof(wxInt32); memcpy(pMemory, keyBuffer.GetData(), keyLength); pMemory += keyLength; memcpy(pMemory, valueBuffer.GetData(), valueLength); pMemory += valueLength; memcpy(pMemory, sourceBuffer.GetData(), sourceLength); ok = Write((const char *) pBuffer, bufferLength) == bufferLength; delete[] pBuffer; } return ok; }