x
This website is using cookies. We use cookies to ensure that we give you the best experience on our website. More info. That's Fine
HPC:Factor Logo 
 
Latest Forum Activity

Constant frequency output

fragenmensch Page Icon Posted 2005-12-09 1:03 PM
#
Avatar image of fragenmensch
Factorite (Elite)

Posts:
207
Location:
DE-DE
Status:
Hi!
Is it possible, to give out a 300HZ signal through speakers in PocketC(I have got CEAPI).

Marco
 Top of the page
chiark Page Icon Posted 2005-12-12 6:45 AM
#
Avatar image of chiark
H/PC Sensei

Posts:
1,330
Location:
North of England
Status:
I've never written anything sound-wise on WinCE, but I'll try to help.

1 - Write code to create your 300Hz signal at the appropriate . This is fairly trivial - just dump the values into an appropriately sized array. The sample rates are derived from CD audio (44.1KHz), so choose a sample rate of 11.025, 22.5 or 44.1KHz, and choose whether you'll be using 8 or 16 bit resolution

2 - Use the waveOut... calls with the appropriate structures. There's an example here that'll get you started.

Alternatively, write a WAV file with a 300Hz sample and just play that using an existing player set to loop?

I don't know if CEAPI has support for the waveOut structures/calls, but it should do.

Cheers,
Nick.
 Top of the page
fragenmensch Page Icon Posted 2005-12-12 11:50 AM
#
Avatar image of fragenmensch
Factorite (Elite)

Posts:
207
Location:
DE-DE
Status:
Sorry, this doesnt help me really:-(
CEAPI has support for the waveOut structures; but how do I create the signal??

Marco
 Top of the page
chiark Page Icon Posted 2005-12-12 1:15 PM
#
Avatar image of chiark
H/PC Sensei

Posts:
1,330
Location:
North of England
Status:
OK, let's assume you're working at 44.1khz, 16 bit signals and you want a sine wave output.

Actually, rather than re-inventing the wheel you could just download a 300Hz sample from the net - google it.

Or if you're convinced you want to write a tone generator, then you're basically rendering a sine wave from 0 to 360 degrees into 147 samples. Iterate through a loop 147 times, loading the array with the results and that's your raw data.

for(i=0;i<147;i++) {
buffer=sin(i * (147/360));
}

set up your structures appropriately, telling the structure the size of raw data, the sampling rate, etc, and you just put that at the waveOut stuff.

 Top of the page
fragenmensch Page Icon Posted 2005-12-12 2:47 PM
#
Avatar image of fragenmensch
Factorite (Elite)

Posts:
207
Location:
DE-DE
Status:
Thanks. Making a WAV wouldn't be the right way for me, because of adjusting duration, and frequency of the sound.

Marco
 Top of the page
chiark Page Icon Posted 2005-12-12 5:06 PM
#
Avatar image of chiark
H/PC Sensei

Posts:
1,330
Location:
North of England
Status:
OK, if you're needing a more generic tone generator then the 147 comes from 44,100 / 300...

You should be able to work stuff out from there
 Top of the page
fragenmensch Page Icon Posted 2005-12-20 12:15 PM
#
Avatar image of fragenmensch
Factorite (Elite)

Posts:
207
Location:
DE-DE
Status:
În file WaveFile.cpp in the sample, there I don't understand some bits:

#define WF_OFFSET_FORMATTAG 20
#define WF_OFFSET_CHANNELS 22
#define WF_OFFSET_SAMPLESPERSEC 24
#define WF_OFFSET_AVGBYTESPERSEC 28
#define WF_OFFSET_BLOCKALIGN 32
#define WF_OFFSET_BITSPERSAMPLE 34
#define WF_OFFSET_DATASIZE 40
#define WF_OFFSET_DATA 44
#define WF_HEADER_SIZE WF_OFFSET_DATA


// set file length
fseek(m_pFile, 0, SEEK_END);
m_nLength = ftell(m_pFile) - WF_HEADER_SIZE;

// set the format attribute members
fseek(m_pFile, 0, SEEK_SET);
fread(aHeader, 1, WF_HEADER_SIZE, m_pFile);
m_Format.wFormatTag = *((WORD*) (aHeader + WF_OFFSET_FORMATTAG));
m_Format.nChannels = *((WORD*) (aHeader + WF_OFFSET_CHANNELS));
m_Format.nSamplesPerSec = *((DWORD*) (aHeader + WF_OFFSET_SAMPLESPERSEC));
m_Format.nAvgBytesPerSec = *((DWORD*) (aHeader + WF_OFFSET_AVGBYTESPERSEC));
m_Format.nBlockAlign = *((WORD*) (aHeader + WF_OFFSET_BLOCKALIGN));
m_Format.wBitsPerSample = *((WORD*) (aHeader + WF_OFFSET_BITSPERSAMPLE));


I am searching for FTELL and the meaning of aHeader so that I can port it to PocketC.

Marco
 Top of the page
Snappy! Page Icon Posted 2005-12-20 7:00 PM
#
Avatar image of Snappy!
H/PC Elder

Posts:
1,712
Location:
New Mexico, US
Status:
I presume the code fragment is related or from http://dev.openwengo.com/trac/openwengo/trac.cgi/browser/libs/sound/src/win32/playsound/SoundFile.cpp?rev=1193

69 static const int WF_OFFSET_DATA = 44;
70 static const int WF_HEADER_SIZE = WF_OFFSET_DATA;
71
72 BYTE aHeader[WF_HEADER_SIZE]; // <--- HERE
73
74 //Set file length
75 fseek(_soundFile, 0, SEEK_END);
76 _soundFileLength = ftell(_soundFile) - WF_HEADER_SIZE;
 Top of the page
fragenmensch Page Icon Posted 2005-12-21 1:18 PM
#
Avatar image of fragenmensch
Factorite (Elite)

Posts:
207
Location:
DE-DE
Status:
I took the samples from http://www.pocketpcdn.com/articles/samples/PlayWav.zip and I found this example through chiarks' post.

Marco
 Top of the page
Snappy! Page Icon Posted 2005-12-21 7:25 PM
#
Avatar image of Snappy!
H/PC Elder

Posts:
1,712
Location:
New Mexico, US
Status:
fragenmensch - 2005-12-21 11:18 AM

I took the samples from http://www.pocketpcdn.com/articles/samples/PlayWav.zip and I found this example through chiarks' post.

Marco


I downloaded the above file, opened the zip, opened WaveFile.cpp ... lo and behold,

The definition of aHeader is right there in the first line of the Open function. Have you tried searching for it? btw, I opened it in notepad and not eVC as I don't have it installed right now ... and there was no searching done by me anyway.

BYTE aHeader[WF_HEADER_SIZE];

WF_HEADER_SIZE is defined right at the end of the constants declaration block in the same file. (Not a very good practise to have constant declarations in a source file if you ask me, though its not written by someone else. Such declarations are usually in header files.)
 Top of the page
fragenmensch Page Icon Posted 2005-12-22 12:36 PM
#
Avatar image of fragenmensch
Factorite (Elite)

Posts:
207
Location:
DE-DE
Status:
Snappy! - 2005-12-22 1:25 AM

fragenmensch - 2005-12-21 11:18 AM

I took the samples from http://www.pocketpcdn.com/articles/samples/PlayWav.zip and I found this example through chiarks' post.

Marco


I downloaded the above file, opened the zip, opened WaveFile.cpp ... lo and behold,

The definition of aHeader is right there in the first line of the Open function. Have you tried searching for it? btw, I opened it in notepad and not eVC as I don't have it installed right now ... and there was no searching done by me anyway.

BYTE aHeader[WF_HEADER_SIZE];

WF_HEADER_SIZE is defined right at the end of the constants declaration block in the same file. (Not a very good practise to have constant declarations in a source file if you ask me, though its not written by someone else. Such declarations are usually in header files.)


I did not want to find where they are declared;i only want to know how to PORT them, sorry...

Marco
 Top of the page
Snappy! Page Icon Posted 2005-12-22 5:33 PM
#
Avatar image of Snappy!
H/PC Elder

Posts:
1,712
Location:
New Mexico, US
Status:
fragenmensch - 2005-12-22 10:36 AM


I did not want to find where they are declared;i only want to know how to PORT them, sorry...

Marco


hmmm ... so you want to port them to which platform/language? I must have missed that part of your intention in your earlier post.

And if you do want to port them, wouldn't you need to know its original declaration so that you can port it?

Maybe someone else can help out here ...
 Top of the page
fragenmensch Page Icon Posted 2005-12-23 6:36 AM
#
Avatar image of fragenmensch
Factorite (Elite)

Posts:
207
Location:
DE-DE
Status:
PocketC, and it was in the post with the codeblock where I said this.I want to port the whole example to PocketC CE.

Marco
 Top of the page
fragenmensch Page Icon Posted 2005-12-23 6:45 AM
#
Avatar image of fragenmensch
Factorite (Elite)

Posts:
207
Location:
DE-DE
Status:
PocketC, and it was in the post with the codeblock where I said this.I want to port the whole example to PocketC CE.

Marco
 Top of the page
Snappy! Page Icon Posted 2005-12-23 7:29 PM
#
Avatar image of Snappy!
H/PC Elder

Posts:
1,712
Location:
New Mexico, US
Status:
fragenmensch - 2005-12-23 4:36 AM

PocketC, and it was in the post with the codeblock where I said this.I want to port the whole example to PocketC CE.

Marco


Ah I see ... missed that.
 Top of the page
Jump to forum:
Seconds to generate: 0.25 - Cached queries : 54 - Executed queries : 27