Path: ...!weretis.net!feeder6.news.weretis.net!i2pn.org!i2pn2.org!.POSTED!not-for-mail From: fir 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: 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; ibig_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