-3

I would like to record speaker's output of my morse code. The code is written in C based on Beep function to play the beep sound. I am using Audacity to record the speaker's output. Here is the code :

/* Send  character  in  morse  code */
void  MCSendChar(unsigned  char ch){
    unsigned  char a = asciiToMC(ch);
    unsigned  char n = a & 0x07 , j;

    for(j = 0; j < n; j++) {
        if((0x80 & a) != 0)
            Beep(500,40);
        else
            Beep(500,120);

        a = a << 1;
        //  Inter  Symbol spacing
        Beep(0,40); 
    }

    //  Inter  character  space
    Beep(0,120);
}

I have a confusion about setting the frequency and the wpm. Also, when I tried to decode the recorded file using an online web decoder, the results are not correct at all. Any Ideas ?

  • 2
    What is your problem? Is the created sound incorrect? Is decoding the audacity recordings incorrect? These are very different questions and you should focus on one. In your code there is no relation to audacity at all. – Gerhardh Dec 07 '20 at 12:43
  • @Gerhardh, when I play the recorded audio file on the website, it is not decoded correctly, So I think it is due to my code – Didou Abdidou Dec 07 '20 at 12:46
  • 1
    You don't show the word spacing which should be 7 dit-times so 280. – Weather Vane Dec 07 '20 at 12:47
  • 1
    If you think it is the generation of the sound, you need to verify manually. E.g. slow down the sound to be able to recognize it with your own ears instead of a program. Or visually inspect the waveform recorded. – Gerhardh Dec 07 '20 at 12:49
  • 2
    Have you checked the output visually? You should print the di-dah-dit sequence. I see you coded a 1 as dit and a 0 as dah, is that true? – Weather Vane Dec 07 '20 at 12:51
  • @WeatherVane, yes I coded a 1 as dit and a 0 as dah – Didou Abdidou Dec 07 '20 at 12:58
  • Well does it *sound* right? If you encode `VVV` you should hear "di-di-di-dah, di-di-di-dah, di-di-di-dah." – Weather Vane Dec 07 '20 at 13:01
  • @WeatherVane, I print the di-dah-dit, it is correct, but the sound is not correct – Didou Abdidou Dec 07 '20 at 13:03
  • I have just tried using the Windows `Beep()` function and the timing is erratic. And if I output 4 dits, only 3 come out of the speakers. – Weather Vane Dec 07 '20 at 13:11
  • When the duration is `81` or more it works ok, but when it is `80` or less it does not (Windows 7). – Weather Vane Dec 07 '20 at 13:14
  • @WeatherVane, I just used the CwGet tool to listen to the output, it shows letters "e" and "t" sequence – Didou Abdidou Dec 07 '20 at 13:21
  • I used my ears, with a very simple program to emit 4 beeps and gaps, with varying duration from command line input. I think that `Beep()` is probably a very blunt tool. – Weather Vane Dec 07 '20 at 13:22
  • @Gerhardh, I print the di dit dah in the terminal, they are ok, but the sound seems incorrect – Didou Abdidou Dec 07 '20 at 13:28
  • @WeatherVane, is there any other solution to hear the correct sound ? – Didou Abdidou Dec 07 '20 at 13:29
  • 1
    Construct your own `.WAV` file ?? Perhaps with a third party library. – Weather Vane Dec 07 '20 at 13:31
  • I have got this to work using `Sleep()` instead of a beeping with `0` frequency. But the timing is still rather erratic. – Weather Vane Dec 07 '20 at 13:45
  • If you construct the audio file directly in the program, the timing will be exact. – Ian Abbott Dec 07 '20 at 16:47
  • @lan Abbott, I started to construct my wave audio file as follow : ```typedef struct { WAVE_FILE_HEADER_T header; uint8_t* byteArray; // for 8 bit sound } DATA_CHUNK; ``` – Didou Abdidou Dec 08 '20 at 08:56

1 Answers1

0

Assuming Beep() is the win32 function, from MSDN on the dwFreq parameter:

The frequency of the sound, in hertz. This parameter must be in the range 37 through 32,767 (0x25 through 0x7FFF).

So you must implement the pauses by some other means than using Beep(), for example using Sleep()

vmt
  • 832
  • 6
  • 16