• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

C++ WaveFile类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了C++中WaveFile的典型用法代码示例。如果您正苦于以下问题:C++ WaveFile类的具体用法?C++ WaveFile怎么用?C++ WaveFile使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



在下文中一共展示了WaveFile类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C++代码示例。

示例1: OpenWaveDevice

int GMSynthDLL::ThreadProc()
{
	if (live)
	{
		if (seqMode & seqPlay)
			ldTm = 0.02;
		else
			ldTm = 0.20;
		OpenWaveDevice();
		inmgr.SetWaveOut(&wvd);
	}
	else
	{
		if (wvf.OpenWaveFile(outFileName, 2))
		{
			OnEvent(SEQEVT_SEQSTOP, NULL);
			return GMSYNTH_ERR_FILEOPEN;
		}
		inmgr.SetWaveOut(&wvf);
	}
	inmgr.Reset();
	seq.SequenceMulti(inmgr, stTime, endTime, seqMode);
	if (live)
	{
		bsInt32 drain = (bsInt32) (synthParams.sampleRate * (ldTm * 4));
		while (--drain > 0)
			inmgr.Tick();
		CloseWaveDevice();
	}
	else
		wvf.CloseWaveFile();
	return GMSYNTH_NOERROR;
}
开发者ID:travisgoodspeed,项目名称:basicsynth,代码行数:33,代码来源:GMSynth.cpp


示例2: Speak

void FaceController::Speak(WaveFile &wave) {
    m_visemes.clear();

    //Calculate which visemes to use from the wave file data
    float soundLength = wave.GetLength();
    float maxAmp = wave.GetMaxAmplitude() * 0.3f;

    for (float i=0.0f; i<soundLength; i += 0.1f) {
        short amp = wave.GetAverageAmplitude(i, i + 0.1f);
        float p = min(amp / maxAmp, 1.0f);

        if (p < 0.2f) {
            m_visemes.push_back(Viseme(0, 0.0f, i));
        }
        else if (p < 0.4f) {
            float prc = max((p - 0.2f) / 0.2f, 0.3f);
            m_visemes.push_back(Viseme(3, prc, i));
        }
        else if (p < 0.7f) {
            float prc = max((p - 0.4f) / 0.3f, 0.3f);
            m_visemes.push_back(Viseme(1, prc, i));
        }
        else {
            float prc = max((p - 0.7f) / 0.3f, 0.3f);
            m_visemes.push_back(Viseme(4, prc, i));
        }
    }


    m_visemeIndex = 1;
    m_speechTime = 0.0f;
}
开发者ID:7zhang,项目名称:studies,代码行数:32,代码来源:faceController.cpp


示例3: memset

LRESULT CMainDlg::OnSaveWave(WORD /*wNotifyCode*/, WORD wID, HWND /*hWndCtl*/, BOOL& /*bHandled*/)
{
	char fileName[MAX_PATH];
	memset(fileName, 0, sizeof(fileName));
	OPENFILENAME ofn;
	memset(&ofn, 0, sizeof(ofn));
	ofn.lStructSize = sizeof(ofn);
	ofn.hwndOwner = m_hWnd;
	ofn.lpstrFilter = "Sound Files(*.wav)\0*.wav\0All Files(*.*)\0*.*\0";
	ofn.nFilterIndex = 1;
	ofn.lpstrFile = fileName;
	ofn.lpstrDefExt = ".wav";
	ofn.nMaxFile = MAX_PATH;
	ofn.Flags = OFN_OVERWRITEPROMPT;
	
	if (GetSaveFileName (&ofn))
	{
		double frq = GetFrequency();
		GenWaveI wv;
		wv.InitWT(frq, WT_USR(0));
		EnvGen eg;
		eg.InitEG(1.0, 2.0, 0.05, 0.05);
		WaveFile wvf;
		wvf.OpenWaveFile(fileName, 2);
		long totalSamples = (long) (2.0 * synthParams.sampleRate);
		for (long n = 0; n < totalSamples; n++)
			wvf.Output1(eg.Gen() * wv.Gen());
		wvf.CloseWaveFile();

	}
	return 0;
}
开发者ID:travisgoodspeed,项目名称:basicsynth,代码行数:32,代码来源:MainDlg.cpp


示例4: Save

bool MonoRecorder::Save(const std::string& fn, bool norm, float norm_max) {
	WaveFile w;
	const RecorderTrack& to_save = *(save_processed ? processed_tracks[0] : tracks[0]);
	w.FromFloat(&to_save[0],to_save.getLength(),norm,norm_max);
	w.Save(fn.c_str());
	return true;
}
开发者ID:aothms,项目名称:ear,代码行数:7,代码来源:MonoRecorder.cpp


示例5: Save

bool StereoRecorder::Save(const std::string& fn, bool norm, float norm_max) {
	WaveFile w;
	const RecorderTrack& left  = *(save_processed ? processed_tracks[0] : tracks[0]);
	const RecorderTrack& right = *(save_processed ? processed_tracks[1] : tracks[1]);
	w.FromFloat(&left[0],&right[0],left.getLength(),right.getLength(),norm);
	w.Save(fn.c_str());
	return true;
}
开发者ID:aothms,项目名称:ear,代码行数:8,代码来源:StereoRecorder.cpp


示例6: main

int main(void)
{
	WaveFile myFile;
	
	myFile.loadWave("DAFT.wav");
	WaveFIR::LPF(myFile, 100, 100, 0, myFile.length-1);
	//myFile.normalize();
	myFile.saveWave("TEST.wav");
	
	return 0;
}
开发者ID:Phryxia,项目名称:PWave,代码行数:11,代码来源:wTest.cpp


示例7: EnterCriticalSection

// Destroy
BOOL AudioStream::Destroy (void)
{
	BOOL fRtn = SUCCESS;

	EnterCriticalSection(&write_lock);
	
	// Stop playback
	Stop ();

	// Release DirectSound buffer
	if (m_pdsb) {
		m_pdsb->Release ();
		m_pdsb = NULL;
		Snd_sram -= m_cbBufSize;
	}

	// Delete WaveFile object
	if (m_pwavefile) {
		m_pwavefile->Close();
		free(m_pwavefile);
		m_pwavefile = NULL;
	}

	status = ASF_FREE;

	LeaveCriticalSection(&write_lock);

	return fRtn;
}
开发者ID:NonCreature0714,项目名称:freespace2,代码行数:30,代码来源:AudioStr.cpp


示例8: ENTER_CRITICAL_SECTION

// Destroy
BOOL AudioStream::Destroy(void)
{
	BOOL fRtn = SUCCESS;

	ENTER_CRITICAL_SECTION(write_lock);

	// Stop playback
	Stop();

	// Release DirectSound buffer
	if (m_pdsb)
	{
		m_pdsb->Release();
		m_pdsb = NULL;
		Snd_sram -= m_cbBufSize;
	}

	// Delete WaveFile object
	if (m_pwavefile)
	{
		m_pwavefile->Close();
		vm_free(m_pwavefile);
		m_pwavefile = NULL;
	}

	status = ASF_FREE;

	LEAVE_CRITICAL_SECTION(write_lock);

	return fRtn;
}
开发者ID:,项目名称:,代码行数:32,代码来源:


示例9: CopyFrom

bool WaveFile::CopyFrom(WaveFile& other)
{
	const size_t transferBufSize = 4096;

	if (!writeFile) {
		error = "Copy to an unopened file";
		return false;
	} else if (!other.readFile) {
		error = "Copy from an unopened file";
		return false;
	}

	try {
		// allocate the transfer buffer
		char* transferBuffer = new char[transferBufSize];
		unsigned long bytesRead = 0;

		try {
			if (!other.ResetToStart())
				throw error = "Couldn't reset input file to start";

			while (bytesRead < other.dataLength) {
				// calculate the size of the next buffer
				size_t bytesToRead = (size_t) min(transferBufSize,
					size_t(other.dataLength - bytesRead));

				// read the buffer
				if (fread(transferBuffer, 1, bytesToRead, other.readFile->filep())
					!= bytesToRead)
					throw error = "Error reading samples from input file";
				bytesRead += bytesToRead;

				// write the buffer
				if (fwrite(transferBuffer, 1, bytesToRead, writeFile) != bytesToRead)
					throw error = "Error writing samples to output file";
				dataLength += bytesToRead;
				changed = true;
			}

			// delete the transfer buffer
			delete[] transferBuffer;
		} catch (...) {
			delete[] transferBuffer;
			throw error;
		}
	} catch (...) {
		return false;
	}

	return true;
}
开发者ID:DewerZHT,项目名称:Project-Voice,代码行数:51,代码来源:WAVE.cpp


示例10: ShowErrors

static void ShowErrors(WaveFile& from, WaveFile& to)
{
	bool any = from.GetError() || to.GetError();

	if (from.GetError())
		cout << "Error on input: " << from.GetError() << "." << endl;

	if (to.GetError())
		cout << "Error on output: " << to.GetError() << "." << endl;

	if (!any)
		cout << "Success." << endl;
}
开发者ID:DewerZHT,项目名称:Project-Voice,代码行数:13,代码来源:WAVE.cpp


示例11: main

int main(int , char **)
{
	WaveFile wf;

	wf.SetupFormat();

	if (!wf.OpenWrite("A440.wav")) {
		cout << "Can't open for writing: " << wf.GetError();
		return 1;
	}

	const dataLength = 1 /*sec*/ * wf.GetSampleRate();  // in samples

	float alpha = 0;
	for (int i = 0; i < dataLength; i++) {
		wf.WriteSample(sin(alpha) / 2);

		alpha += 2 * M_PI * frequency / wf.GetSampleRate();
	}

	return 0;
}
开发者ID:DewerZHT,项目名称:Project-Voice,代码行数:22,代码来源:A440.cpp


示例12: ShowFormat

static void ShowFormat(WaveFile& wave, bool details = true)
{
	cout
		<< "Format:           " << wave.GetFormatType()
		<< (wave.IsCompressed()? " (compressed)" : " (PCM)") << endl
		<< "Channels:         " << wave.GetNumChannels() << endl
		<< "Sample rate:      " << wave.GetSampleRate() << endl
		<< "Bytes per second: " << wave.GetBytesPerSecond() << endl
		<< "Bytes per sample: " << wave.GetBytesPerSample() << endl
		<< "Bits per channel: " << wave.GetBitsPerChannel() << endl
		<< "Bytes:            " << wave.GetDataLength() << endl
		<< "Samples:          " << wave.GetNumSamples() << endl
		<< "Seconds:          " << wave.GetNumSeconds() << endl;

	if(wave.GetFile())
		cout << "File pointer:     " << ftell(wave.GetFile()) << endl;
	else
		cout << "File pointer:     null" << endl;

	if (details) {
		string type, value;
		if (wave.GetFirstExtraItem(type, value)) {
			cout << "Extra data:" << endl;
			do {
				cout << "  " << type << ": " << value << endl;
			} while (wave.GetNextExtraItem(type, value));
		}
		wave.ResetToStart();
	}
	pause();
}
开发者ID:DewerZHT,项目名称:Project-Voice,代码行数:31,代码来源:WAVE.cpp


示例13: Assert

// Create
BOOL AudioStream::Create (LPSTR pszFilename, AudioStreamServices * pass)
{
	BOOL fRtn = SUCCESS;    // assume success

	Assert(pszFilename);
	Assert(pass);

	m_pass = pass;
	Init_Data();

	if (pszFilename && m_pass) {
		// Create a new WaveFile object
	
		m_pwavefile = (WaveFile *)malloc(sizeof(WaveFile));
		Assert(m_pwavefile);

		if (m_pwavefile) {
			// Call constructor
			m_pwavefile->Init();
			// Open given file
			m_pwavefile->m_bits_per_sample_uncompressed = m_bits_per_sample_uncompressed;
			if (m_pwavefile->Open (pszFilename)) {
				// Calculate sound buffer size in bytes
				// Buffer size is average data rate times length of buffer
				// No need for buffer to be larger than wave data though
				m_cbBufSize = (m_pwavefile->GetUncompressedAvgDataRate () * m_nBufLength) / 1000;
				nprintf(("SOUND", "SOUND => Stream buffer created using %d bytes\n", m_cbBufSize));
				// m_cbBufSize = (m_cbBufSize > m_pwavefile->GetDataSize ()) ? m_pwavefile->GetDataSize () : m_cbBufSize;

				//nprintf(("Sound", "SOUND => average data rate = %d\n\r", m_pwavefile->GetUncompressedAvgDataRate ()));
				//nprintf(("Sound", "SOUND => m_cbBufSize = %d\n\r", m_cbBufSize));

				// Create sound buffer
				HRESULT hr;
				memset (&m_dsbd, 0, sizeof (DSBUFFERDESC));
				m_dsbd.dwSize = sizeof (DSBUFFERDESC);
				m_dsbd.dwBufferBytes = m_cbBufSize;
				m_dsbd.lpwfxFormat = &m_pwavefile->m_wfmt;
				m_dsbd.dwFlags = DSBCAPS_STATIC | DSBCAPS_CTRLPAN | DSBCAPS_CTRLVOLUME | DSBCAPS_LOCSOFTWARE;

				hr = (m_pass->GetPDS ())->CreateSoundBuffer (&m_dsbd, &m_pdsb, NULL);
				if (hr == DS_OK) {
					// Cue for playback
					Cue ();
					Snd_sram += m_cbBufSize;
				}
				else {
					// Error, unable to create DirectSound buffer
					nprintf(("Sound", "SOUND => Error, unable to create DirectSound buffer\n\r"));
					if (hr == DSERR_BADFORMAT) {
						nprintf(("Sound", "SOUND => Bad format (probably ADPCM)\n\r"));
					}

					fRtn = FAILURE;
				}
			}
			else {
				// Error opening file
				nprintf(("SOUND", "SOUND => Failed to open wave file: %s\n\r", pszFilename));
				m_pwavefile->Close();
				free(m_pwavefile);
				m_pwavefile = NULL;
				fRtn = FAILURE;
			}   
		}
		else {
			// Error, unable to create WaveFile object
			nprintf(("Sound", "SOUND => Failed to create WaveFile object %s\n\r", pszFilename));
			fRtn = FAILURE;
		}
	}
	else {
		// Error, passed invalid parms
		fRtn = FAILURE;
	}

	return (fRtn);
}
开发者ID:NonCreature0714,项目名称:freespace2,代码行数:79,代码来源:AudioStr.cpp


示例14: main

int main(int argc, char *argv[])
{
#if defined(USE_MSXML)
	CoInitialize(0);
#endif

	const char *fname = "data.xml";
	if (argc > 1)
		fname = argv[1];

	InitSynthesizer();

	mix.SetChannels(2);
	mix.MasterVolume(1.0, 1.0);
	mix.ChannelOn(0, 1);
	mix.ChannelOn(1, 1);
	mix.ChannelVolume(0, 1.0);
	mix.ChannelVolume(1, 1.0);
#ifdef ADD_REVERB
	mix.SetFxChannels(1);
	mix.FxInit(0, &rvrb, 0.1);
	mix.FxLevel(0, 0, 0.2);
	mix.FxLevel(0, 1, 0.2);
	rvrb.InitReverb(1.0, 2.0);
#endif

	inMgr.Init(&mix, &wvf);

	inMgr.AddType("Tone", ToneInstr::ToneFactory, ToneInstr::ToneEventFactory);
	inMgr.AddType("ToneFM", ToneFM::ToneFMFactory, ToneFM::ToneFMEventFactory);
	inMgr.AddType("AddSynth", AddSynth::AddSynthFactory, AddSynth::AddSynthEventFactory);
	inMgr.AddType("SubSynth", SubSynth::SubSynthFactory, SubSynth::SubSynthEventFactory);
	inMgr.AddType("FMSynth", FMSynth::FMSynthFactory, FMSynth::FMSynthEventFactory);
	inMgr.AddType("MatrixSynth", MatrixSynth::MatrixSynthFactory, MatrixSynth::MatrixSynthEventFactory);
	inMgr.AddType("WFSynth", WFSynth::WFSynthFactory, WFSynth::WFSynthEventFactory);
	inMgr.AddType("Chuffer", Chuffer::ChufferFactory, Chuffer::ChufferEventFactory);
	inMgr.AddType("ModSynth", ModSynth::ModSynthFactory, ModSynth::ModSynthEventFactory);
	inMgr.AddType("BuzzSynth", BuzzSynth::InstrFactory, BuzzSynth::EventFactory);
	InstrMapEntry *ime = 0;
	while ((ime = inMgr.EnumType(ime)) != 0)
		ime->dumpTmplt = DestroyTemplate;

	XmlSynthDoc doc;
	XmlSynthElem rootNode(&doc);
	if (!doc.Open(fname, &rootNode))
	{
		printf("Cannot open file %s\n", fname);
		exit(1);
	}

	// Optional: use LoadInstrLib(inMgr, fname)
	// but we want to discover the inum values
	// and add sequences programaticaly...

	XmlSynthElem elem(&doc);
	XmlSynthElem *inst = rootNode.FirstChild(&elem);
	while (inst != NULL)
	{
		if (inst->TagMatch("instr"))
		{
			InstrConfig *ent = inMgr.LoadInstr(inst);
			if (strcmp(ent->instrType->GetType(), "WFSynth") == 0)
				AddEvent(ent->inum, 48, 1.0);
			else
				AddSequence(ent->inum, 0.25);
		}

		inst = elem.NextSibling(&elem);
	}
	doc.Close();

	if (wvf.OpenWaveFile("example10.wav", 2))
	{
		printf("Cannot open wavefile for output\n");
		exit(1);
	}
	seq.Sequence(inMgr);

#ifdef ADD_REVERB
	// drain the reverb...
	AmpValue lv;
	AmpValue rv;
	long n = synthParams.isampleRate;
	while (n-- > 0)
	{
		mix.Out(&lv, &rv);
		wvf.Output2(lv, rv);
	}
#endif

	wvf.CloseWaveFile();

	///////////////////////////////////////////////////////////////
	// Code to test instrument save functions...
#define TEST_SAVE_INSTR 1
#ifdef TEST_SAVE_INSTR
	doc.NewDoc("instrlib", &rootNode);
	InstrConfig *inc = inMgr.EnumInstr(0);
	while (inc)
	{
//.........这里部分代码省略.........
开发者ID:travisgoodspeed,项目名称:basicsynth,代码行数:101,代码来源:main.cpp


示例15: main

int main(int argc, char **argv)
{
	// Parsing
	printf("%s\n%s\n", argv[0], argv[1]);
	char targetName[256];
	
	strcpy(targetName, argv[0]);
	
	for(int n=strlen(targetName)-1; n>=0; --n)
	{
		if(targetName[n] != '\\')
		{
			targetName[n] = '\0';
		}
		else
		{
			targetName[n] = '\0';
			break;
		}
	}
	
	strcat(targetName, "\\Data\\Test.dat");
	
	FILE *myFile = fopen(targetName, "wb");
	WaveFile myWave;
	
	if(myFile == NULL)
	{
		printf("Something is wrong\n");
		getchar();
		
		fclose(myFile);
		
		return 0;
	}

	if(argc != 2)
	{
		printf("Drag a WavFile on this icon.\n");
		getchar();
	}
	else
	{
		myWave.loadWave(argv[1]);
		myWave.normalize();
		
		printf("File Name : %s\n", argv[1]);
		
		int buffer;
		
		buffer = myWave.length;
		fwrite(&buffer, sizeof(int), 1, myFile);
		printf("Length : %d\n", buffer);
		
		if(ferror(myFile))
		{
			printf("Something is wrong...\n");
		}
		
		buffer = myWave.sample_rate;
		fwrite(&buffer, sizeof(int), 1, myFile);
		printf("Sample Rate : %d\n", buffer);
		
		for(int n=0; n<myWave.length; ++n)
		{
			if(myWave.data[0][n] >= 1.0)
			{
				buffer = int32_max - 1;
			}
			else if(myWave.data[0][n] < -1.0)
			{
				buffer = -int32_max;
			}
			else
			{
				buffer = int(int32_max*myWave.data[0][n]);
			}
			
			fwrite(&buffer, sizeof(int), 1, myFile);
		}
		
		printf("Done!\n");
	}
	
	fclose(myFile);
	
	return 0;
}
开发者ID:sjw9912,项目名称:OmegaProject,代码行数:88,代码来源:Main.cpp


示例16: PlayWaveFile

void AudioDevice::PlayWaveFile(WaveFile &File, bool LoopForever)
{
#ifdef USE_DIRECTX_AUDIO
    if(_Device == NULL)
    {
        return;
    }
    RemoveVoices(true);

    if(_ActiveSourceVoices.Length() > 4)
    {
        return;
    }

    // Get format of wave file
    WAVEFORMATEX& pwfx = File.Format();
    
    // Create the source voice
    IXAudio2SourceVoice* _SourceVoice;
    HRESULT hr = _Device->CreateSourceVoice( &_SourceVoice, &pwfx );
    Assert(SUCCEEDED(hr), "CreateSourceVoice failed");
    _ActiveSourceVoices.PushEnd(_SourceVoice);
    
    // Submit the wave sample data using an XAUDIO2_BUFFER structure
    XAUDIO2_BUFFER buffer = {0};
    buffer.pAudioData = (BYTE *)File.Data().CArray();
    buffer.Flags = XAUDIO2_END_OF_STREAM;  // tell the source voice not to expect any data after this buffer
    buffer.AudioBytes = File.Data().Length();// * sizeof(DWORD);

    if(LoopForever)
    {
        buffer.LoopBegin = 1;
        buffer.LoopLength = 0;
        buffer.LoopCount = XAUDIO2_LOOP_INFINITE;
    }

    hr = _SourceVoice->SubmitSourceBuffer( &buffer );
    Assert(SUCCEEDED(hr), "SubmitSourceBuffer failed");

    hr = _SourceVoice->Start( 0 );
    Assert(SUCCEEDED(hr), "SubmitSourceBuffer failed");

    //delete[] pbWaveData;

    //Sleep(3000);
    //_SourceVoice->DestroyVoice();
    // Let the sound play
    /*BOOL isRunning = TRUE;
    while( SUCCEEDED( hr ) && isRunning )
    {
        XAUDIO2_VOICE_STATE state;
        pSourceVoice->GetState( &state );
        isRunning = ( state.BuffersQueued > 0 ) != 0;

        // Wait till the escape key is pressed
        if( GetAsyncKeyState( VK_ESCAPE ) )
            break;

        Sleep( 10 );
    }

    // Wait till the escape key is released
    while( GetAsyncKeyState( VK_ESCAPE ) )
        Sleep( 10 );

    pSourceVoice->DestroyVoice();
    SAFE_DELETE_ARRAY( pbWaveData );

    return hr;*/
#endif
}
开发者ID:kbinani,项目名称:dxrip,代码行数:71,代码来源:AudioDevice.cpp


示例17: TestWaveFile

//-----------------------------------------------------------------------------
// WAVE file test
void TestWaveFile() {
    WaveFile file;
    file.Load("/home/abelov/Stuff/View/Sound/Clean Guitar/Clean Guitar_1-12.wav");
}
开发者ID:quantograph,项目名称:SimpleCode,代码行数:6,代码来源:PiTest.cpp


示例18: Cue

// Cue
void AudioStream::Cue (void)
{
	UINT num_bytes_written;

	if (!m_fCued) {
		m_bFade = FALSE;
		m_fade_timer_id = 0;
		m_finished_id = 0;
		m_bPastLimit = FALSE;
		m_lVolume = 0;
		m_lCutoffVolume = -10000;

		m_bDestroy_when_faded = FALSE;

		// Reset buffer ptr
		m_cbBufOffset = 0;

		// Reset file ptr, etc
		m_pwavefile->Cue ();

		// Reset DirectSound buffer
		m_pdsb->SetCurrentPosition (0);

		// Fill buffer with wave data
		WriteWaveData (m_cbBufSize, &num_bytes_written,0);

		m_fCued = TRUE;
	}
}
开发者ID:NonCreature0714,项目名称:freespace2,代码行数:30,代码来源:AudioStr.cpp


示例19: WriteSilence

// WriteSilence
//
// Writes silence to sound buffer. This is a helper method used by
// ServiceBuffer; it's not exposed to users of the AudioStream class.
BOOL AudioStream::WriteSilence(UINT size)
{
	HRESULT hr;
	LPBYTE lpbuf1 = NULL;
	LPBYTE lpbuf2 = NULL;
	DWORD dwsize1 = 0;
	DWORD dwsize2 = 0;
	DWORD dwbyteswritten1 = 0;
	DWORD dwbyteswritten2 = 0;
	BOOL fRtn = SUCCESS;

	// Lock the sound buffer
	hr = m_pdsb->Lock(m_cbBufOffset, size, (void**)(&lpbuf1), &dwsize1, (void**)(&lpbuf2), &dwsize2, 0);
	if (hr == DS_OK)
	{

		// Get silence data for this file format. Although word sizes vary for different
		// wave file formats, ::Lock will always return pointers on word boundaries.
		// Because silence data for 16-bit PCM formats is 0x0000 or 0x00000000, we can
		// get away with writing bytes and ignoring word size here.
		BYTE bSilence = m_pwavefile->GetSilenceData();

		// Write silence to sound buffer. Because the sound buffer is circular, we may have to
		// do two write operations if locked portion of buffer wraps around to start of buffer.
		memset(lpbuf1, bSilence, dwsize1);
		dwbyteswritten1 = dwsize1;

		// Second write required?
		if (lpbuf2)
		{
			memset(lpbuf2, bSilence, dwsize2);
			dwbyteswritten2 = dwsize2;
		}

		// Update our buffer offset and unlock sound buffer
		m_cbBufOffset = (m_cbBufOffset + dwbyteswritten1 + dwbyteswritten2) % m_cbBufSize;
		//		m_pdsb->Unlock (lpbuf1, dwbyteswritten1, lpbuf2, dwbyteswritten2);
		m_pdsb->Unlock(lpbuf1, dwsize1, lpbuf2, dwsize2);
	}
	else
	{
		// Error locking sound buffer
		nprintf(("SOUND", "SOUND ==> Error, unable to lock sound buffer in AudioStr\n"));
		fRtn = FAILURE;
	}

	return (fRtn);
}
开发者ID:,项目名称:,代码行数:52,代码来源:


示例20: Generate

AmpValue Generate(float duration, GenUnit *wv, EnvGen *eg, AmpValue in = 1.0)
{
	long totalSamples = (long) ((duration * synthParams.sampleRate) + 0.5);
	AmpValue volume;
	AmpValue value;
	AmpValue peak = 0.0;

	eg->Reset();

	for (long n = 0; n < totalSamples; n++)
	{
		volume = eg->Gen();
		value = wv->Sample(in);
		if (value > peak)
			peak = value;
		wvf.Output1(value * volume);
	}
	return peak;
}
开发者ID:travisgoodspeed,项目名称:basicsynth,代码行数:19,代码来源:main.cpp



注:本文中的WaveFile类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C++ WaveTrack类代码示例发布时间:2022-05-31
下一篇:
C++ WaveClip类代码示例发布时间:2022-05-31
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap