- 001
- 002
- 003
- 004
- 005
- 006
- 007
- 008
- 009
- 010
- 011
- 012
- 013
- 014
- 015
- 016
- 017
- 018
- 019
- 020
- 021
- 022
- 023
- 024
- 025
- 026
- 027
- 028
- 029
- 030
- 031
- 032
- 033
- 034
- 035
- 036
- 037
- 038
- 039
- 040
- 041
- 042
- 043
- 044
- 045
- 046
- 047
- 048
- 049
- 050
- 051
- 052
- 053
- 054
- 055
- 056
- 057
- 058
- 059
- 060
- 061
- 062
- 063
- 064
- 065
- 066
- 067
- 068
- 069
- 070
- 071
- 072
- 073
- 074
- 075
- 076
- 077
- 078
- 079
- 080
- 081
- 082
- 083
- 084
- 085
- 086
- 087
- 088
- 089
- 090
- 091
- 092
- 093
- 094
- 095
- 096
- 097
- 098
- 099
- 100
void riffoser_track_writeriff(struct riffoser_track * track,char * filename,riffoser_samplerate_t samplerate,riffoser_bitspersample_t bitspersample) {
FILE * fp;
unsigned long i1,i2,i3,i4,i5,i6,fpi;
unsigned char c1,bytespersample;
unsigned char * skipbuf;
float fret,val;
long ival;
unsigned char nomorewaves;
riffoser_channel_t chan;
bytespersample=bitspersample/8;
fp=fopen(filename,"wb");
i1=track->channels*samplerate*bytespersample*track->length;
i2=4+24+8+i1+(i1%2>0?1:0);
riffoser_writestr("RIFF");
riffoser_writeint(4,4+24+8+i1+(i1%2>0?1:0));
riffoser_writestr("WAVEfmt ");
riffoser_writeint(4,16);
riffoser_writeint(2,1);
riffoser_writeint(2,track->channels);
riffoser_writeint(4,samplerate);
riffoser_writeint(4,bytespersample*track->channels*samplerate);
riffoser_writeint(2,bytespersample*track->channels);
riffoser_writeint(2,bytespersample*8);
riffoser_writestr("data");
riffoser_writeint(4,i1);
if (i1%2>0)
riffoser_writeint(1,0);
i1=0;
i3=track->waves_count;
i6=0;
nomorewaves=0;
while (1) {
chan=i1%track->channels;
if (i3==track->waves_count&&!nomorewaves) {
i5=i1;
0&&printf("%lu: finding nearest wave...\n",i1);
for (i2=0;i2<track->waves_count;i2++){
if ((track->wavestates[i2]->state==RIFFOSER_WAVESTATE_IDLE)&&(((i3==track->waves_count))||(RIFFOSER_RENDER___FROM(track->wavestates[i2])<=i5))&&(RIFFOSER_RENDER___FROM(track->wavestates[i2])>=i6)) {
0&&printf("%lu: found wave %lu with from %f\n",i1,i2,RIFFOSER_RENDER___FROM(track->wavestates[i2]));
i3=i2;
i5=RIFFOSER_RENDER___FROM(track->wavestates[i2]);
}
else {
0&&printf("%lu: skipping wave %lu\n",i1,i2);
}
}
if (i3!=track->waves_count)
0&&printf("next wave will be %lu at %f\n",i3,RIFFOSER_RENDER___FROM(track->wavestates[i3]));
else nomorewaves=1;
}
c1=0;
val=0;
for (i2=0;i2<track->waves_count;i2++){
if (track->wavestates[i2]->state==RIFFOSER_WAVESTATE_RENDERING) {
if (RIFFOSER_RENDER___TO(track->wavestates[i2])<i1) {
track->wavestates[i2]->state=RIFFOSER_WAVESTATE_FINISHED;
0&&printf("%lu: wave %lu finished\n",i1,i2);
} else {
if (track->wavestates[i2]->channel==chan) {
// printf("correct channel\n");
track->wavestates[i2]->samplenum++;
if (track->wavestates[i2]->samplenum>RIFFOSER_RENDER___WSC(track->waves[i2]))
track->wavestates[i2]->samplenum-=RIFFOSER_RENDER___WSC(track->waves[i2]);
0&&printf("%lu: rendering wave %lu (%f-%f), samplenum is %f (%f%%)\n",i1,i2,RIFFOSER_RENDER___FROM(track->wavestates[i2]),RIFFOSER_RENDER___TO(track->wavestates[i2]),track->wavestates[i2]->samplenum,RIFFOSER_RENDER___WPP(track->waves[i2],track->wavestates[i2]->samplenum));
RIFFOSER_WAVE_FUNC(track->waves[i2],RIFFOSER_RENDER___WPP(track->waves[i2],track->wavestates[i2]->samplenum));
fret=fret*track->waves[i2]->amplitude/200;
// replace for now
val=fret;
}
else {
// printf("wrong channel ( %u / %u )\n",track->wavestates[i2]->channel,chan);
}
c1=1;
}
}
}
if (bytespersample==1) {
ival=round(val*2.56)-128;
if (ival>127)
ival=127;
}
else if (bytespersample==2) {
ival=round(val*655.36);
if (ival>65535)
ival=65535;
}
else if (bytespersample==4) {
ival=round(val*42949672.96);
if (ival>4294967295)
ival=4294967295;
}
riffoser_writeint(bytespersample,ival);
if (c1==0) {
if (i3!=track->waves_count) {
0&&printf("%lu: warping to position %lu\n",i1,i5);
i4=(i5-i1)*bytespersample;
skipbuf=malloc(i4);
memset(skipbuf,0,i4);
riffoser_writebuf(i4,skipbuf);
Полная версия - https://github.com/anon4ik/riffoser/blob/master/libriffoser.c
PascalGovno 31.10.2012 09:54 # +1
Steve_Brown 31.10.2012 11:07 # +4
(4294967295 == 0xFFFFFFFF)
Что-то даже и не соображу что тут происходит. Надо покурить правила приведения знаковых/беззнаковых значений...
TarasB 31.10.2012 11:15 # +1
kostoprav 31.10.2012 11:30 # 0
[00:51:51] :3: ih mozg ne sposoben k bolee 4istomu vospriyatiyu koda
[00:51:57] :3: poetomu ni4evo krome oop im ne ostayotsya
[00:52:06] :3: a vot vy nepravy 4to za64i64yaete oop kak 4toto edinstvenno vernoe
roman-kashitsyn 31.10.2012 11:39 # +3
kostoprav 31.10.2012 11:40 # 0
roman-kashitsyn 31.10.2012 11:44 # 0
kostoprav 31.10.2012 11:45 # +1
TarasB 31.10.2012 11:49 # +5
absolut 31.10.2012 11:58 # +5
TarasB 31.10.2012 13:50 # +3
TarasB 31.10.2012 11:43 # +3
ололо
kostoprav 31.10.2012 21:40 # +4
[10/30/2012 11:26:51 PM] :3: 0&&printf eto ok
[10/30/2012 11:26:55 PM] :3: kompilyatorom ignoriruetsya
[10/30/2012 11:27:15 PM] :3: 0&& - 3 simvola
[10/30/2012 11:27:18 PM] :3: ifdef - STROKI KODA
bormand 01.11.2012 05:32 # +7
A eto dzva simvola. Avtor idet nahui so svoim dlinnim 0&&.
PascalGovno 01.11.2012 16:37 # +1
FireBurd 01.11.2012 12:42 # 0
wvxvw 01.11.2012 14:19 # 0
kostoprav 01.11.2012 14:55 # +2
Lowezar 31.10.2012 19:40 # +1
Lowezar 01.11.2012 16:19 # +2
Вообще нечто потустороннее... Раз он так любит "сокращать", почему не сократил до i1%2 ... :)
TarasB 01.11.2012 17:17 # +4