Jump to content
  • Advertisement
Sign in to follow this  

[c++]Single buffer

This topic is 3046 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hey, Here is my question, Still trying to examine it in theory. Is there a way to convert audio buffer (pcm wave data) from 22 khz mono to 22 khz stereo while using one (The same source) buffer? The source buffer is twice as big. (sketch theory) - 10 samples array : [0][1][2][3][4][5][6][7][8][9]... (Store incoming sample = 1) [0][0][2][3][4][5][6][7][8][9]... (Set previous stored sample = 1, Store 2) [0][0][1][1][4][5][6][7][8][9]... [0][0][1][1][2][2][6][7][8][9]... I guess what i am trying to say is, The legitimate procedure will be : void Sound22MonoTo22Stereo(Datatype* Source, Datatype* Dest, Datatype size) procedure : while(size) { copy the data from dest to source twice Source = Dest Source[i +1] = Dest Forward the source by 2 and dest by 1. } Now since i only need to copy the source into itself is there a logical method i can achieve it with one buffer? (I don`t wish to copy the buffer into a different buffer, Or use two buffers.) *The answer could be : "No , It won`t work", But i just want to make sure with the high chain of programming command, Before i take the old road.

// I find assembly much easier since in 'C', i need to perform a lot of datatype conversions.

// This method isn`t working since each iteration requires more registers to store previous samples...

// What have i tried...

void __fastcall Convert22MonoTo22Stereo(char* Source, unsigned int* BufferSize)

		push eax
		push ebx
		push edi

//		prefetch Source

		mov ebx, dword ptr [BufferSize]
		mov eax, dword ptr [ebx]

		test eax, eax

		jz FEND

		mov bx, word ptr [ecx]
		mov dx, word ptr [ecx + 2]
		mov di, word ptr [ecx + 4]
		mov word ptr [ecx], bx
		mov word ptr [ecx +2], bx
		mov bx, dx
		mov dx, di

		add ecx, 4

		mov di, [ecx]

		sub eax, 1
		jnz LOOP1
		movd eax, dword ptr [BufferSize]
		shl eax, 1
		movd dword ptr [BufferSize], eax

		pop eax
		pop ebx
		pop edi

void __fastcall Convert22MonoTo22Stereo(short* Source, unsigned int* BufferSize)
    short Sample1 = Source[0]
    short Sample2;

    for(int i = 0; i < BufferSize; i++)
          Sample2 = Source[i + 1]
          Source     = Sample1
          Source[i + 1] = Sample1
          Sample1 = Sample2

Thanks in advance. [Edited by - Illasera on February 16, 2010 10:48:29 AM]

Share this post

Link to post
Share on other sites
Original post by Sneftel
Just start from the end and move backwards, so you always have enough space.

Thank you :)

Share this post

Link to post
Share on other sites
Sign in to follow this  

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!