int32 func__sndopen(qbs* filename,qbs* requirements,int32 passed){ sndsetup(); if (new_error) return 0; static qbs *s1=NULL; if (!s1) s1=qbs_new(0,0); static qbs *req=NULL; if (!req) req=qbs_new(0,0); static qbs *s3=NULL; if (!s3) s3=qbs_new(0,0); static uint8 r[32]; static int32 i,i2,i3; //check requirements memset(r,0,32); if (passed){ if (requirements->len){ i=1; qbs_set(req,qbs_ucase(requirements));//convert tmp str to perm str nextrequirement: i2=func_instr(i,req,qbs_new_txt(","),1); if (i2){ qbs_set(s1,func_mid(req,i,i2-i,1)); }else{ qbs_set(s1,func_mid(req,i,req->len-i+1,1)); } qbs_set(s1,qbs_rtrim(qbs_ltrim(s1))); if (qbs_equal(s1,qbs_new_txt("SYNC"))){r[0]++; goto valid;} if (qbs_equal(s1,qbs_new_txt("VOL"))){r[1]++; goto valid;} if (qbs_equal(s1,qbs_new_txt("PAUSE"))){r[2]++; goto valid;} if (qbs_equal(s1,qbs_new_txt("LEN"))){r[3]++; goto valid;} if (qbs_equal(s1,qbs_new_txt("SETPOS"))){r[4]++; goto valid;} error(5); return 0;//invalid requirements valid: if (i2){i=i2+1; goto nextrequirement;} for (i=0;i<32;i++) if (r[i]>1){error(5); return 0;}//cannot define requirements twice }//->len }//passed qbs_set(s1,qbs_add(filename,qbs_new_txt_len("\0",1)));//s1=filename+CHR$(0) if (!r[0]){//NOT SYNC if (snd_stream_handle){error(5); return 0;}//stream in use } //load file if (s1->len==1) return 0;//return invalid handle if null length string static int32 fh,result; static int64 lof; fh=gfs_open(s1,1,0,0); if (fh<0) return 0; lof=gfs_lof(fh); static uint8* content; content=(uint8*)malloc(lof); if (!content){gfs_close(fh); return 0;} result=gfs_read(fh,-1,content,lof); gfs_close(fh); if (result<0){free(content); return 0;} //identify file format static snd_sequence_struct *seq; //OGG? #ifdef DEPENDENCY_AUDIO_DECODE_OGG if (lof>=3){ if (content[0]==79){ if (content[1]==103){ if (content[2]==103){//"Ogg" seq=snd_decode_ogg(content,lof); goto got_seq; }}} }//3 #endif //WAV? #ifdef DEPENDENCY_AUDIO_DECODE_WAV if (lof>=12){ if ((*(uint32*)&content[8])==0x45564157){//WAVE seq=snd_decode_wav(content,lof); goto got_seq; }//WAVE } #endif //assume mp3! //MP3? #ifdef DEPENDENCY_AUDIO_DECODE_MP3 seq=snd_decode_mp3(content,lof); #endif got_seq: free(content); if (seq==NULL) return 0; //convert sequence (includes sample rate conversion etc etc) //just perform sample_rate fix for now... //1. 8->16bit conversion and/or edian conversion static int32 incorrect_format; incorrect_format=0; if (seq->bits_per_sample!=16) incorrect_format=1; if (seq->is_unsigned) incorrect_format=1; //todo... if (seq->endian==???) //this section does not fix the frequency, only the bits per sample //and signed-ness of the data if (incorrect_format){ static int32 bps; bps=seq->bits_per_sample/8; static int32 samples; samples=seq->data_size/bps; static uint8 *new_data; if (bps!=2){ new_data=(uint8*)malloc(samples*2); }else{ new_data=seq->data; } static int32 i,v; for (i=0;i<samples;i++){ //read original value v=0; if (bps==1){ if (seq->is_unsigned){ v=*(uint8*)(seq->data+i*1); v=(v-128)*256; }else{ v=*(int8*)(seq->data+i*1); v=v*128; } } if (bps==2){ if (seq->is_unsigned){ v=*(uint16*)(seq->data+i*2); v=v-32768; }else{ v=*(int16*)(seq->data+i*2); } } //place new value into array ((int16*)new_data)[i]=v; }//i if (bps!=2){free(seq->data); seq->data=new_data; seq->data_size=samples*2;} //update seq info seq->bits_per_sample=16; seq->is_unsigned=0; }//incorrect format //2. samplerate conversion if (seq->sample_rate != snd_frequency) { //need to resample seq->data //create new resampler SpeexResamplerState *state; state = speex_resampler_init(seq->channels, seq->sample_rate, snd_frequency, SPEEX_RESAMPLER_QUALITY_MIN, NULL); if (!state) { //NULL means failure free(seq->data); return 0; } //allocate new memory for output int32 out_samples_max = ((double)seq->data_size / seq->channels / 2) * ((((double)snd_frequency) / ((double)seq->sample_rate)) + 0.1) + 100;//10%+100 extra samples as a buffer-zone int16 *resampled = (int16 *)malloc(out_samples_max * seq->channels * sizeof(int16)); if (!resampled) { free(seq->data); return 0; } //establish data sizes //in_len will be set by the resampler to number of samples processed spx_uint32_t in_len = seq->data_size / seq->channels / 2; // divide by 2 because 2byte samples, divive by #channels because function wants it per-channel //out_len will be set to the number of samples written spx_uint32_t out_len; //resample! if (speex_resampler_process_interleaved_int(state, (spx_int16_t *)seq->data, &in_len, (spx_int16_t *)resampled, &out_len) != RESAMPLER_ERR_SUCCESS) { //Error free(resampled); free(seq->data); speex_resampler_destroy(state); return 0; } //destroy the resampler anyway speex_resampler_destroy(state); //establish real size of new data and update seq free(seq->data); //That was the old data seq->data_size = out_len * seq->channels * 2; //remember out_len is perchannel, and each sample is 2 bytes seq->data = (uint8_t *)realloc(resampled, seq->data_size); //we overestimated the array size before, so make it the correct size now if (!seq->data) { //realloc could fail free(resampled); return 0; } seq->sample_rate = snd_frequency; } if (seq->channels==1){ seq->data_mono=seq->data; seq->data_mono_size=seq->data_size; } if (seq->channels==2){ seq->data_stereo=seq->data; seq->data_stereo_size=seq->data_size; } if (seq->channels>2) return 0; //attach sequence to handle (& inc. refs) //create snd handle static int32 handle; handle=list_add(snd_handles); static snd_struct *snd; snd=(snd_struct*)list_get(snd_handles,handle); snd->internal=0; snd->type=2; snd->seq=seq; snd->volume=1.0; snd->capability=r[0]*SND_CAPABILITY_SYNC+r[1]*SND_CAPABILITY_VOL+r[2]*SND_CAPABILITY_PAUSE+r[3]*SND_CAPABILITY_LEN+r[4]*SND_CAPABILITY_SETPOS; if (!r[0]){ snd->streamed=1;//NOT SYNC snd_stream_handle=handle; } return handle; }
qbs* WHATISMYIP(){ //changed name from FUNC_WHATISMYIP to WHATISMYIP qbs *tqbs; ptrszint tmp_long; int32 tmp_fileno; uint32 qbs_tmp_base=qbs_tmp_list_nexti; uint8 *tmp_mem_static_pointer=mem_static_pointer; uint32 tmp_cmem_sp=cmem_sp; //data.txt qbs *_FUNC_WHATISMYIP_STRING_WHATISMYIP=NULL; if (!_FUNC_WHATISMYIP_STRING_WHATISMYIP)_FUNC_WHATISMYIP_STRING_WHATISMYIP=qbs_new(0,0); float *_FUNC_WHATISMYIP_SINGLE_C=NULL; if(_FUNC_WHATISMYIP_SINGLE_C==NULL){ _FUNC_WHATISMYIP_SINGLE_C=(float*)mem_static_malloc(4); *_FUNC_WHATISMYIP_SINGLE_C=0; } qbs *_FUNC_WHATISMYIP_STRING_E=NULL; if (!_FUNC_WHATISMYIP_STRING_E)_FUNC_WHATISMYIP_STRING_E=qbs_new(0,0); qbs *_FUNC_WHATISMYIP_STRING_X=NULL; if (!_FUNC_WHATISMYIP_STRING_X)_FUNC_WHATISMYIP_STRING_X=qbs_new(0,0); byte_element_struct *byte_element_5276=NULL; if (!byte_element_5276){ if ((mem_static_pointer+=12)<mem_static_limit) byte_element_5276=(byte_element_struct*)(mem_static_pointer-12); else byte_element_5276=(byte_element_struct*)mem_static_malloc(12); } float *_FUNC_WHATISMYIP_SINGLE_T=NULL; if(_FUNC_WHATISMYIP_SINGLE_T==NULL){ _FUNC_WHATISMYIP_SINGLE_T=(float*)mem_static_malloc(4); *_FUNC_WHATISMYIP_SINGLE_T=0; } qbs *_FUNC_WHATISMYIP_STRING_A2=NULL; if (!_FUNC_WHATISMYIP_STRING_A2)_FUNC_WHATISMYIP_STRING_A2=qbs_new(0,0); qbs *_FUNC_WHATISMYIP_STRING_A=NULL; if (!_FUNC_WHATISMYIP_STRING_A)_FUNC_WHATISMYIP_STRING_A=qbs_new(0,0); float *_FUNC_WHATISMYIP_SINGLE_DOTS=NULL; if(_FUNC_WHATISMYIP_SINGLE_DOTS==NULL){ _FUNC_WHATISMYIP_SINGLE_DOTS=(float*)mem_static_malloc(4); *_FUNC_WHATISMYIP_SINGLE_DOTS=0; } float *_FUNC_WHATISMYIP_SINGLE_START=NULL; if(_FUNC_WHATISMYIP_SINGLE_START==NULL){ _FUNC_WHATISMYIP_SINGLE_START=(float*)mem_static_malloc(4); *_FUNC_WHATISMYIP_SINGLE_START=0; } float *_FUNC_WHATISMYIP_SINGLE_X=NULL; if(_FUNC_WHATISMYIP_SINGLE_X==NULL){ _FUNC_WHATISMYIP_SINGLE_X=(float*)mem_static_malloc(4); *_FUNC_WHATISMYIP_SINGLE_X=0; } double fornext_value5279; double fornext_finalvalue5279; double fornext_step5279; uint8 fornext_step_negative5279; byte_element_struct *byte_element_5280=NULL; if (!byte_element_5280){ if ((mem_static_pointer+=12)<mem_static_limit) byte_element_5280=(byte_element_struct*)(mem_static_pointer-12); else byte_element_5280=(byte_element_struct*)mem_static_malloc(12); } float *_FUNC_WHATISMYIP_SINGLE_A=NULL; if(_FUNC_WHATISMYIP_SINGLE_A==NULL){ _FUNC_WHATISMYIP_SINGLE_A=(float*)mem_static_malloc(4); *_FUNC_WHATISMYIP_SINGLE_A=0; } qbs *_FUNC_WHATISMYIP_STRING_IP=NULL; if (!_FUNC_WHATISMYIP_STRING_IP)_FUNC_WHATISMYIP_STRING_IP=qbs_new(0,0); if (new_error) goto exit_subfunc; mem_lock *sf_mem_lock; new_mem_lock(); sf_mem_lock=mem_lock_tmp; sf_mem_lock->type=3; *_FUNC_WHATISMYIP_SINGLE_C=func__openclient(qbs_new_txt_len("TCP/IP:80:www.qb64.net",22)); qbs_cleanup(qbs_tmp_base,0); if ((-(*_FUNC_WHATISMYIP_SINGLE_C== 0 ))||new_error){ goto exit_subfunc; } qbs_set(_FUNC_WHATISMYIP_STRING_E,qbs_add(func_chr( 13 ),func_chr( 10 ))); qbs_cleanup(qbs_tmp_base,0); qbs_set(_FUNC_WHATISMYIP_STRING_X,qbs_add(qbs_new_txt_len("GET /ip.php HTTP/1.1",20),_FUNC_WHATISMYIP_STRING_E)); qbs_cleanup(qbs_tmp_base,0); qbs_set(_FUNC_WHATISMYIP_STRING_X,qbs_add(qbs_add(_FUNC_WHATISMYIP_STRING_X,qbs_new_txt_len("Host: www.qb64.net",18)),_FUNC_WHATISMYIP_STRING_E)); qbs_cleanup(qbs_tmp_base,0); qbs_set(_FUNC_WHATISMYIP_STRING_X,qbs_add(qbs_add(_FUNC_WHATISMYIP_STRING_X,qbs_new_txt_len("",0)),_FUNC_WHATISMYIP_STRING_E)); qbs_cleanup(qbs_tmp_base,0); sub_put2(qbr(*_FUNC_WHATISMYIP_SINGLE_C),NULL,byte_element((uint64)_FUNC_WHATISMYIP_STRING_X->chr,_FUNC_WHATISMYIP_STRING_X->len,byte_element_5276),0); qbs_cleanup(qbs_tmp_base,0); *_FUNC_WHATISMYIP_SINGLE_T=func_timer(NULL,0); do{ if ((-((func_timer(NULL,0)-*_FUNC_WHATISMYIP_SINGLE_T)>( 5 )))||new_error){ sub_close(qbr(*_FUNC_WHATISMYIP_SINGLE_C),1); goto exit_subfunc; } sub__delay( 0.1E+0 ); sub_get2(qbr(*_FUNC_WHATISMYIP_SINGLE_C),NULL,_FUNC_WHATISMYIP_STRING_A2,0); qbs_cleanup(qbs_tmp_base,0); qbs_set(_FUNC_WHATISMYIP_STRING_A,qbs_add(_FUNC_WHATISMYIP_STRING_A,_FUNC_WHATISMYIP_STRING_A2)); qbs_cleanup(qbs_tmp_base,0); *_FUNC_WHATISMYIP_SINGLE_DOTS= 0 ; *_FUNC_WHATISMYIP_SINGLE_START= 0 ; fornext_value5279= 1 ; fornext_finalvalue5279=_FUNC_WHATISMYIP_STRING_A->len; fornext_step5279= 1 ; if (fornext_step5279<0) fornext_step_negative5279=1; else fornext_step_negative5279=0; if (new_error) goto fornext_error5279; goto fornext_entrylabel5279; while(1){ fornext_value5279=fornext_step5279+(*_FUNC_WHATISMYIP_SINGLE_X); fornext_entrylabel5279: *_FUNC_WHATISMYIP_SINGLE_X=fornext_value5279; qbs_cleanup(qbs_tmp_base,0); if (fornext_step_negative5279){ if (fornext_value5279<fornext_finalvalue5279) break; }else{ if (fornext_value5279>fornext_finalvalue5279) break; } fornext_error5279:; *_FUNC_WHATISMYIP_SINGLE_A=qbs_asc(_FUNC_WHATISMYIP_STRING_A,qbr(*_FUNC_WHATISMYIP_SINGLE_X)); qbs_cleanup(qbs_tmp_base,0); if (((-(*_FUNC_WHATISMYIP_SINGLE_A>= 48 ))&(-(*_FUNC_WHATISMYIP_SINGLE_A<= 57 )))||new_error){ if ((-(*_FUNC_WHATISMYIP_SINGLE_START== 0 ))||new_error){ *_FUNC_WHATISMYIP_SINGLE_START=*_FUNC_WHATISMYIP_SINGLE_X; } }else{ if (((-(*_FUNC_WHATISMYIP_SINGLE_A== 46 ))&(-(*_FUNC_WHATISMYIP_SINGLE_START!= 0 )))||new_error){ *_FUNC_WHATISMYIP_SINGLE_DOTS=*_FUNC_WHATISMYIP_SINGLE_DOTS+ 1 ; }else{ if ((-(*_FUNC_WHATISMYIP_SINGLE_DOTS== 3 ))||new_error){ qbs_set(_FUNC_WHATISMYIP_STRING_IP,func_mid(_FUNC_WHATISMYIP_STRING_A,qbr(*_FUNC_WHATISMYIP_SINGLE_START),qbr(*_FUNC_WHATISMYIP_SINGLE_X-*_FUNC_WHATISMYIP_SINGLE_START),1)); qbs_cleanup(qbs_tmp_base,0); goto dl_exit_5277; } *_FUNC_WHATISMYIP_SINGLE_START= 0 ; *_FUNC_WHATISMYIP_SINGLE_DOTS= 0 ; } } } fornext_exit_5278:; }while(1); dl_exit_5277:; sub_close(qbr(*_FUNC_WHATISMYIP_SINGLE_C),1); qbs_set(_FUNC_WHATISMYIP_STRING_WHATISMYIP,_FUNC_WHATISMYIP_STRING_IP); qbs_cleanup(qbs_tmp_base,0); exit_subfunc:; free_mem_lock(sf_mem_lock); //free.txt qbs_free(_FUNC_WHATISMYIP_STRING_E); qbs_free(_FUNC_WHATISMYIP_STRING_X); qbs_free(_FUNC_WHATISMYIP_STRING_A2); qbs_free(_FUNC_WHATISMYIP_STRING_A); qbs_free(_FUNC_WHATISMYIP_STRING_IP); if ((tmp_mem_static_pointer>=mem_static)&&(tmp_mem_static_pointer<=mem_static_limit)) mem_static_pointer=tmp_mem_static_pointer; else mem_static_pointer=mem_static; cmem_sp=tmp_cmem_sp; qbs_maketmp(_FUNC_WHATISMYIP_STRING_WHATISMYIP);return _FUNC_WHATISMYIP_STRING_WHATISMYIP; }