Sign in to follow this  

[c++]Single buffer

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[i] = Dest[i] Source[i +1] = Dest[i] 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[i]     = 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

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this