#include "../../config.h"

#ifdef HAVE_CONFIG_H
#include "config.h"
#endif

#include <fcntl.h>
#include <unistd.h>

//#include <math.h> //zaradi log hv

#include "mpegsound.h"

/* IOCTL */
#ifdef SOUND_VERSION
#define IOCTL(a,b,c)		ioctl(a,b,&c)
#else
#define IOCTL(a,b,c)		(c = ioctl(a,b,c) )
#endif

//#include <QRegExp>//hv
//#include <QtGui>

//char *Rawtodata::defaultdevice=(char*)"/dev/dsp";
//bool Rawtodata::defaultdrv=false; //hv
//int Rawtodata::buffering = 88200;//=500ms
//static char *saved_device;
//static bool saved_drv = false;
//static int buff_hv;

//static double vol_win = 0.0001;

/*******************/
/* Rawtodata class */
/*******************/
// Rawtodata class
Rawtodata::~Rawtodata()
{}
bool Rawtodata::initialize(char*)
{
    audiobuffersize = 4096;
    //audiobuffersize = 1024;
    //size_ftt_window =345;//za 11025 i 30s
    //count_ftt_window = 0;
    // audiobuffersize = 345;
    //saved_device = Rawtodata::defaultdevice;
    //buff_hv = Rawtodata::buffering;
    //qDebug()<<"initialize";
    return true;
}
int Rawtodata::getprocessed(void)
{
	//qDebug()<<"gerprocessed";
    return 1;
}
bool Rawtodata::setsoundtype(int stereo,int samplesize,int speed)
{
    // pauza e prez tazi (procedura + resetsoundtype(void)) a stop e samo resetsoundtype(void)
    rawstereo=stereo;
    rawsamplesize=samplesize;
    rawspeed=speed;

    if (stereo==0)
        rawchannels = 1;
    if (stereo==1)
        rawchannels = 2;

    //forcetomono=forceto8=false;
    //return resetsoundtype();
    //qDebug()<<stereo<<samplesize<<speed;
    return true;
}
/*
bool Rawtodata::resetsoundtype(void)
{
//qDebug()<<"LINressss";


    return win_resetsoundtype(saved_device,rawchannels,rawsamplesize,rawspeed,false,buff_hv);
}
*/
bool Rawtodata::putblock(void *buffer,int size)
{
    /*short *shortArr=new short[size/2];
    char *buf = (char*)buffer;
    for (int i = 0; i <size/2 ; i++)
    shortArr[i] = ((short)(( buf[i*2] & 0xff )|( buf[i*2 + 1] << 8 )));
    SentData(shortArr,size/2,true);    
    qDebug()<<(int)buf[0];
    qDebug()<<(int)buf[1];
    qDebug()<<(int)shortArr[0];*/

    emit SentData((short*)buffer,size/2,true);//1.27 psk rep fopen

    /*short *k = (short*)buffer;
    qDebug()<<k[0]<<"0";
    qDebug()<<k[1]<<"1";
    qDebug()<<k[2]<<"3";
    qDebug()<<k[4]<<"4";
    qDebug()<<k[5]<<"5";
    qDebug()<<k[6]<<"6";*/

    return true;
}
int Rawtodata::getblocksize(void)
{
    return audiobuffersize;
}




