[programming in c] bitmap gramophone

Liste des GroupesRevenir à cl c  
Sujet : [programming in c] bitmap gramophone
De : fir (at) *nospam* grunge.pl (fir)
Groupes : comp.lang.c
Date : 01. Apr 2024, 15:30:39
Autres entêtes
Organisation : i2pn2 (i2pn.org)
Message-ID : <uuecth$3nt1b$1@i2pn2.org>
User-Agent : Mozilla/5.0 (Windows NT 5.1; rv:27.0) Gecko/20100101 Firefox/27.0 SeaMonkey/2.24
writing on this bytes container i thought
it could be fun to  run a code that plays
array of shorts as 22100Hz audio, (1 channel, 16 bit)
(winanpi has functions for this: waveOut)
i load the vav onto screen when given 16bit
value i draw as a pixel so i got the sound drawed
(as blue-green mess)
44k hz sound better (22k souns a bit like from
casette recorder) but 22k makes more sound to seen
on screen (like 20 seconds instead of 10 seconds)
than i run the playback just from teh screen data
so i can play bitmap data like sorta of bitmap
gramophone (hovever playing bitmaps genarally makes
mostly if not ony some buzzes not much interesting)
so i decided to generate waves (using sin() ) into that
bitmap wav thinking if i divide given second of
playback onto 50 parts of 0.02 second each and if i
generate sinvaves based on a plot w ill draw with a mouse
(1 pixel y distance from bottom of screen = pitch of
20ms fragment that is playbacking) then i should obtain
something interesting (in theory coz in practice
it rather sounds like f1 8-bit bolid speeding engines up
and down)
the question is how to exactly generate those sinvaves
based the plot
right now i got something like (which is probably crap)
(but its total draft writing at the night as a series
of experminets with brain off)  (thats why one need
to slow down and rethink it slowly)
  int wave_pos =0;
  void buffer_add_sinwave(int len, float a, int cycle)
  {
    for(int i=wave_pos; i<wave_pos+len; i++)
        {
          if(i>big_ofscreen_buffer_size_x*big_ofscreen_buffer_size_y) continue;
             float t = (i%cycle)*1./cycle;
             float s = sin(2*3.14159*t);
           //  float w = (s+1.001)/2.01;
             w=s;
             unsigned int val=a*(127*256*w);
             big_ofscreen_buffer[i] =  val;//+rand()%5;
         }
    wave_pos+=len;
       return;
       ///////////////////////////////////////
}
    int tempo = 22050/44.1;
    float volume = 0.3;
    int base = 22050/1;
  void buffer_add_sinwaves()
  {
    wave_pos =0;
    for(int i=0; i<floats_size;i++)
     buffer_add_sinwave(tempo, floats2[i]/frame_size_y, base/floats[i]);
  }
two notes
1) i dont in fack know what those 16 bit walues are, they are
unsigned or signed
2) here the frequency it semms i generate cycle (of sinvavw) = 22khz/y
which means for y = 10 i got 2200 pixels wave so its 10 hz
for y=100 i 220 wave - so its 100 hz ?
(i get a little bit (i mean uch) tired of this but it
overally seems somewhat interesting)

Date Sujet#  Auteur
1 Apr 24 * [programming in c] bitmap gramophone5fir
1 Apr 24 `* Re: [programming in c] bitmap gramophone4fir
2 Apr 24  `* Re: [programming in c] bitmap gramophone3fir
2 Apr 24   `* Re: [programming in c] bitmap gramophone2Spiros Bousbouras
2 Apr 24    `- Re: [programming in c] bitmap gramophone1fir

Haut de la page

Les messages affichés proviennent d'usenet.

NewsPortal