Deutsch   English   Français   Italiano  
<uuecth$3nt1b$1@i2pn2.org>

View for Bookmarking (what is this?)
Look up another Usenet article

Path: ...!weretis.net!feeder6.news.weretis.net!i2pn.org!i2pn2.org!.POSTED!not-for-mail
From: fir <fir@grunge.pl>
Newsgroups: comp.lang.c
Subject: [programming in c] bitmap gramophone
Date: Mon, 01 Apr 2024 15:30:39 +0200
Organization: i2pn2 (i2pn.org)
Message-ID: <uuecth$3nt1b$1@i2pn2.org>
MIME-Version: 1.0
Content-Type: text/plain; charset=ISO-8859-1; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Mon, 1 Apr 2024 13:30:25 -0000 (UTC)
Injection-Info: i2pn2.org;
	logging-data="3929131"; mail-complaints-to="usenet@i2pn2.org";
	posting-account="+ydHcGjgSeBt3Wz3WTfKefUptpAWaXduqfw5xdfsuS0";
User-Agent: Mozilla/5.0 (Windows NT 5.1; rv:27.0) Gecko/20100101 Firefox/27.0 SeaMonkey/2.24
X-Spam-Checker-Version: SpamAssassin 4.0.0
Bytes: 3403
Lines: 83



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)