Thread: WAV File - Summary In A Row Of Sine Waves... Need Help

  1. #1
    Registered User
    Join Date
    Feb 2021
    Posts
    3

    WAV File - Summary In A Row Of Sine Waves... Need Help

    Hello,


    I'm trying to do some project at C because I'm new at coding,


    I making a Decoder and Encoder for Morse code.
    I use morse configuration by user free choice of: frequency[Hz] of dot, frequency[Hz] of dash, time of dot[ms], time of dash[ms], and delay between dot and dash[ms].


    the user writing the configuration and the text, the text converted to morse code.
    now I want to make an output WAV file of the morse code text (dot and dash) with the user configuration (part of the WAV file).


    I tried a lot of examples from the internet and GitHub and I didn't succeed...


    this part of my code:
    Code:
    #define _CRT_SECURE_NO_WARNINGS
    #include <stdio.h> 
    #include <stdlib.h> 
    #include "config.h"
    #include <conio.h>
    
    
    int transmit()
    {
    //---------------------------------Setting & Variables-----------------------------------------//
    	system("cls");//clear screen
    	//char T[25] = { '\0' }; //transmit user input variable 
    	char str[25],str1[100]; //str contain the text from user, str1 contain the morse convert
    	int i = 0, j = 0;
    	int count = 0;
    	//unsigned int frequancy_dash, frequancy_dot, dash_time, dot_time, delay_dd;
    	//int index = 0,c;
    	//char buffer[256]; //to read from config.txt
    	struct Config config; //create stuck type Config named config
    	int configmain(void);
    //-------------------------------Read Configuration file---------------------------------------//
    	FILE* fp;
    	fp = fopen("config.txt", "r");
    	if (fp == NULL) //check if the file exist if not --> go to config function to create new config.txt file
    	{
    		config();
    	}
    	else //if config.txt empty --> go to config function to create new config.txt file
    	{
    		fseek(fp, 0, SEEK_END);//start from 0 location to the end of the file
    		if (ftell(fp) == 0) //check if the file empty
    		{
    			config();
    		}
    	}
    	rewind(fp);//back to file start
    
    
    	while (fgets(buffer, sizeof(buffer), fp)) //read all config.txt
    	{
    		puts(buffer);
    	}
    	
    	rewind(fp);//back to file start
    	while (fgets(buffer, sizeof(buffer), fp))
    	{
    		if (!parse(buffer))
    		{
    			fclose(fp);
    			return 0;
    		}
    	}
    	gets(enter);//recive the 'Enter' pressing from user 
    
    
    	fclose(fp);
    
    
    */
    
    
    //new config v1.2//
    //-------------------------------Read Configuration file---------------------------------------//
    	FILE* fp;
    	fp = fopen("config.txt", "r");
    	if (fp == NULL) //check if the file exist if not --> go to config function to create new config.txt file
    	{
    		printf("error reading config.txt - Press Enter\n"); //UI error message
    		system("cls"); //clear screen
    		configmain();
    		return 1;
    	}	
    	system("cls"); //clear screen
    
    
    //--------------------------------Display configuration----------------------------------------//
    	config_read(&config, "config.txt"); //read config.txt file
    	printf("Exists configuration:\n"); //UI message
    	printf("Freq dot is %i\n", config.freq_dot); // UI Display what is in config file
    	printf("Freq dash is %i\n", config.freq_dash);
    	printf("Time dot is %i\n", config.time_dot);
    	printf("Time dash is %i\n", config.time_dash);
    	printf("Delay %i\n", config.delay);
    
    
    //-----------------------------------Recive user text------------------------------------------//
    	int morse(); //define morse function
    	morse(str,str1); //convert string to morse
    
    
    
    
            //WAV_morse_create(str1) // <-------------------[[[here i don't know what to do... i dont have this function its only for example ]]]



    ill glad for your help.

  2. #2
    Registered User
    Join Date
    Apr 2013
    Posts
    3
    Also cross-posted in Dream-In-Code.

  3. #3
    Registered User
    Join Date
    May 2012
    Posts
    491
    It's really a signals processing issue rather than a C issue.

    The body of the sound (dot dash) can be either a pure sine wave or a combination of sine waves. In a real application you would probably use a fast Fourier transform, but because you are using C, repeated calls to the function sin() will probably be fast enough.

    However you will get a click if you transition from silence to a sine wave and vice versa.So you need a short section where you ramp up the volume slowly. This is quite easy to do - use the same sine wave, then apply a linear ramp to it, for the start and tails. There are other ways and there's a whole art to filtering, but this should be OK for a morse simulator.
    I'm the author of MiniBasic: How to write a script interpreter and Basic Algorithms
    Visit my website for lots of associated C programming resources.
    https://github.com/MalcolmMcLean


  4. #4
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    38,544
    > I use morse configuration by user free choice of: frequency[Hz] of dot, frequency[Hz] of dash, time of dot[ms], time of dash[ms], and delay between dot and dash[ms].
    There is only one frequency in Morse code.

    All the information is encoded in the dots and dashes themselves. In it's audio form, the actual frequency of the tone is a constant (it only has to be audible).
    Whether you
    see "---...---"
    or hear <beeeep><beeeep><beeeep><beep><beep><beep><beeeep> <beeeep><beeeep>
    doesn't change the message being communicated.

    > I tried a lot of examples from the internet and GitHub and I didn't succeed...
    Try writing your own code and learn how to do it.
    You don't become a good cook by rummaging through the garbage bins of restaurants.


    You're a long way off having to worry about the audio side of things when you can't even read the config file.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Need to draw sine waves using C
    By Satya in forum C Programming
    Replies: 8
    Last Post: 05-20-2017, 12:07 AM
  2. Replies: 26
    Last Post: 10-30-2013, 11:34 PM
  3. File summary attributes
    By jorgepino in forum Windows Programming
    Replies: 5
    Last Post: 06-24-2005, 11:31 AM
  4. File summary attributes
    By Lee the Weasle in forum C++ Programming
    Replies: 6
    Last Post: 06-24-2005, 08:36 AM
  5. C Programming for sine waves drawing
    By pattop in forum C Programming
    Replies: 11
    Last Post: 05-13-2004, 03:52 AM

Tags for this Thread