Comments (7)
Ok thanks @Jacajack. I'll see if I can clean this up a bit and then add it to this feature.
from cmorse.
Actually, I thought about that before, it's a pretty nice idea 👍
I've been generating WAV files using C before - it's relatively easy to implement. As you said, beeping using some kind of sound library may be little harder. I've used Port Audio before, but I think it's a good idea to question ourselves if it's really worth including it in such small project (obviously, that doesn't mean that we can't at least try! 😝)
from cmorse.
@Jacajack did you implement a WAV library from scratch or use a pre-exiting one?
from cmorse.
It was very basic library - I implemented it by myself.
This was very useful for me: http://soundfile.sapp.org/doc/WaveFormat/
from cmorse.
@jconard3, I found it. It's pretty messy, but there it is
#include <stdio.h>
#include <math.h>
#include <inttypes.h>
#include <stdlib.h>
typedef union
{
struct
{
//RIFF chunk descriptor
char chunkID[4];
uint32_t chunkSize;
char format[4];
//Data chunk
char subchunk1ID[4];
uint32_t subchunk1Size;
uint16_t audioFormat;
uint16_t numChannels;
uint32_t sampleRate;
uint32_t byteRate;
uint16_t blockAlign;
uint16_t bitsPerSample;
//Data chunk
char subchunk2ID[4];
uint32_t subchunk2Size;
};
char raw[44];
} FileWAV;
void makeWAV( FileWAV *wav, uint8_t channels, uint8_t bitsPerSample, uint16_t sampleRate, float duration )
{
wav->chunkID[0] = 'R';
wav->chunkID[1] = 'I';
wav->chunkID[2] = 'F';
wav->chunkID[3] = 'F';
wav->chunkSize = 36 + channels * sampleRate * bitsPerSample / 8 * duration;
wav->format[0] = 'W';
wav->format[1] = 'A';
wav->format[2] = 'V';
wav->format[3] = 'E';
wav->subchunk1ID[0] = 'f';
wav->subchunk1ID[1] = 'm';
wav->subchunk1ID[2] = 't';
wav->subchunk1ID[3] = ' ';
wav->subchunk1Size = 16;
wav->audioFormat = 1;
wav->numChannels = channels;
wav->sampleRate = sampleRate;
wav->byteRate = sampleRate * bitsPerSample / 8;
wav->blockAlign = 2;
wav->bitsPerSample = bitsPerSample;
wav->subchunk2ID[0] = 'd';
wav->subchunk2ID[1] = 'a';
wav->subchunk2ID[2] = 't';
wav->subchunk2ID[3] = 'a';
wav->subchunk2Size = channels * sampleRate * bitsPerSample / 8 * duration;
}
int main( )
{
float duration = 60.0f, frequency = 440.0f;
FileWAV wav;
uint32_t i;
uint16_t *sine = malloc( 44100 * 2 * duration );
char *sineb = (char *) sine;
//Samples: 44100
//Channels: 1
//SamplesPerSec: 44100
//ByteRate: 88200
//BitsPerSample: 16
makeWAV( &wav, 1, 16, 44100, 60.0f );
for ( i = 0; i < 44100 * duration; i++ )
sine[i] = 20000.0 * sin( i / ( 44100.0f / frequency ) * 2.0 * M_PI );
for ( i = 0; i < sizeof( FileWAV ); i++ )
putchar( wav.raw[i] );
for ( i = 0; i < 88200 * duration; i++ )
putchar( sineb[i] );
return 0;
}
from cmorse.
A w drugą stronę? czytanie wav i odczytywanie kodów?
przy okazji możesz zobaczyc lcwo.net/ tez Polak pisze ;)
from cmorse.
@letarg0 Aktualnie mam ambitniejsze projekty na głowie, więc nie liczyłbym na taką funkcjonalność w niedalekiej przyszłości, ale oczywiście zawsze możesz otworzyć nowy pull request.
Translation for clarity (if somebody ever reads this):
I currently have more ambitious projects to develop, so I wouldn't expect such functionality to be added anytime soon, but feel free to open a new pull request if you want.
from cmorse.
Related Issues (7)
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from cmorse.