🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: borland.public.cppbuilder.multimedia
Article #433

Re: Recording 24-bit audio (additional info)

#433
From: Mark Jacobs
Date: Thu, 05 Aug 2004 11:13
109 lines
4292 bytes
On Wed, 4 Aug 2004 22:53:25 +0100, Chris Croughton <chris@keristor.net>  
wrote:

> The format has got to be wrong, somehow, because giving floating-point
> (and apparently only 16 bits significant, at that) and only one channel
> is not at all what I'd expect or want.  I can live with FP if I have to,
> but not the missing channel...

I found that WAVEFORMATEX structures need to be naturally discovered on  
the PC using the ACM. Somehow, you have to discover the formats for 24-bit  
sound handling. Remember that 24-bit is 3-bytes per sample, and most  
compilers align structures to 4-byte boundaries - could that be the  
problem? The data buffer is simply a character array (char *) so the byte  
alignment doesn't make a difference in my apps. I have to interpret  
different bits per sample, using different algorithms. However, I did  
notice something peculiar when I went to 8-bit sampling (for VU meters  
etcetera). In the following code snippets, glbwvhdr is the pointer to the  
WAVEHDR structure that is ready and has been "unprepared" successfully.  
Here is my 8-bit code :-

   int  
lv=128-abs((int)glbwvhdr->lpData[0]),rv=128-abs((int)glbwvhdr->lpData[1]);
   if (glbwvhdr->lpData[0]<0) lv=-lv;
   if (glbwvhdr->lpData[1]<0) rv=-rv;
   zcDinMeter1->Value=lv*100/128; // Value is between 0 and 100
   zcDinMeter2->Value=rv*100/128;

Now compare that to my 16-bit code :-

   short *mybf=(short *)glbwvhdr->lpData;
   zcDinMeter1->Value=(int)mybf[0]*100*/32768; // Value is between -100 and  
100
   zcDinMeter2->Value=(int)mybf[1]*100*/32768;

Lord knows what 24-bit decode should look like, or why I have to muck  
about so much with 8-bit samples to get them right!?! But let me just say  
that your symptoms of having barely any signal in the right channel, is  
exactly what I got when I used the 16-bit algorithm (adapted to 8-bit) on  
the 8-bit samples. Perhaps if you use my 8-bit algorithm, but change 128  
to 8388608, and the buffer has to be re-interpreted. Try this :-

   int  
dtlv=(int)glbwvhdr->lpData[0]*256*256+(int)glbwvhdr->lpData[1]*256+(int)glbwvhdr->lpData[2];
   int  
dtrv=(int)glbwvhdr->lpData[3]*256*256+(int)glbwvhdr->lpData[4]*256+(int)glbwvhdr->lpData[5];
   int lv=8388608-abs(dtlv),rv=8388608-abs(dtrv);
   if (glbwvhdr->lpData[0]<0) lv=-lv;
   if (glbwvhdr->lpData[1]<0) rv=-rv;
   zcDinMeter1->Value=lv*100/8388608; // Value is between 0 and 100
   zcDinMeter2->Value=rv*100/8388608;

Does that work? If not, swap the bytes round backwards, so that the first  
2 lines look like this :-

   int  
dtlv=(int)glbwvhdr->lpData[2]*256*256+(int)glbwvhdr->lpData[1]*256+(int)glbwvhdr->lpData[0];
   int  
dtrv=(int)glbwvhdr->lpData[5]*256*256+(int)glbwvhdr->lpData[4]*256+(int)glbwvhdr->lpData[3];

HTH. Let us know how it goes. Cheers,
-- 
Mark Jacobs
DK Computing
http://www.dkcomputing.co.uk
markj atty critical dotty co dotty uk
Technical Details
Message-ID: <opsb9as3elbvaws7@dk-tzx09ucg42z4.s1.sol1.co.uk>
Path: arc1-ca.pugleaf.net!g2news1.google.com!news1.google.com!news.glorb.com!newsfeed00.sul.t-online.de!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mail
References: <slrncgs56p.j46.chris@ccserver.keris.net> <410f6b8a@newsgroups.borland.com> <slrncgvo3t.5n3.chris@ccserver.keris.net> <4110bf9b@newsgroups.borland.com> <41113590$1@newsgroups.borland.com> <slrnch2mml.ofk.chris@ccserver.keris.net>

Show Full Headers
Complete Article Headers
X-Google-Thread: 10d0fc,56d63b5f0bddbea3
X-Google-Attributes: gid10d0fc,public
X-Google-Language: ENGLISH,ASCII-7-bit
Date: Thu, 05 Aug 2004 12:13:41 +0100
Subject: Re: Recording 24-bit audio (additional info)
Newsgroups: borland.public.cppbuilder.multimedia
Reply-To: markjattycriticaldottycodottyuk
References: <slrncgs56p.j46.chris@ccserver.keris.net> <410f6b8a@newsgroups.borland.com> <slrncgvo3t.5n3.chris@ccserver.keris.net> <4110bf9b@newsgroups.borland.com> <41113590$1@newsgroups.borland.com> <slrnch2mml.ofk.chris@ccserver.keris.net>
From: "Mark Jacobs" <markjattycriticaldottycodottyuk>
Organization: DK Computing
Content-Type: text/plain; format=flowed; delsp=yes; charset=iso-8859-15
MIME-Version: 1.0
Content-Transfer-Encoding: Quoted-Printable
Message-ID: <opsb9as3elbvaws7@dk-tzx09ucg42z4.s1.sol1.co.uk>
User-Agent: Opera M2/7.53 (Win32, build 3850)
NNTP-Posting-Host: 81.144.157.8
X-Trace: newsgroups.borland.com 1091704421 81.144.157.8 (5 Aug 2004 04:13:41 -0700)
Lines: 109
Path: arc1-ca.pugleaf.net!g2news1.google.com!news1.google.com!news.glorb.com!newsfeed00.sul.t-online.de!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mail