Cpper
C/C++高级工程师 Android高级软件工程师 IT集成工程师 音频工程师 熟悉c,c++,java,c#,py,js,asp等多种语言 程序猿

#include <stdio.h>
#include 
<errno.h>
#include 
<string.h>
#include 
<unistd.h>
#include 
<fcntl.h>
#include 
<math.h>
#if defined(__OpenBSD__) || defined(__NetBSD__)
#include 
<soundcard.h>
#else
#include 
<sys/soundcard.h>
#endif
#include 
<sys/ioctl.h>
#include 
<sndfile.h>

#define BUFFER_LEN 4096

int _open_default_oss_device(char **dev_path,int id,int blocking);

int main(int argc,char *argv[])
{
    
if(argc<2)
        
return 0;

    SF_INFO info;
    SNDFILE
* file = sf_open(argv[1],SFM_READ,&info);
    
if(!file)
        
return 0;

    printf(
"samplerate:%d\n",info.samplerate);
    printf(
"channel:%d\n",info.channels);

    
char* dsp = NULL;
    
int dp = _open_default_oss_device(&dsp,0,0);
    if(dp < 0)
    {
        printf(
"dsp:%d\n",dp);
        perror("oss bad:");
        sf_close(file);
        return -1; 
    }
    
int tmp = info.channels;
    
int ret = ioctl(dp,SNDCTL_DSP_CHANNELS,&tmp);
    tmp 
= info.samplerate;
    ret 
= ioctl(dp,SNDCTL_DSP_SPEED,&tmp);
    tmp 
= AFMT_S16_LE;
    ioctl(dp,SNDCTL_DSP_SAMPLESIZE,
&tmp);

    
long  len = 0;
    
short buffer[BUFFER_LEN];
    
while((len=sf_read_short(file,buffer,BUFFER_LEN))!=0)
    {
        write(dp,(
char*)buffer,len*2);
    }

    close(dp);
    sf_close(file);
    free(dsp);
    
return 0;
}

int _open_default_oss_device(char **dev_path,int id,int blocking)
{
    
int fd;
    
char buf[80];

    
if(id>0)
    {
        sprintf(buf,
"/dev/sound/dsp%d",id);
        
if(!(*dev_path = strdup(buf)))
            
return -1;
    }
    
else
    {
        
if(!(*dev_path = strdup("/dev/sound/dsp")))
            
return -1;
    }

#ifdef BROKEN_OSS
    fd 
= open(*dev_path, O_WRONLY | O_NONBLOCK);
#else
    fd 
= open(*dev_path, O_WRONLY);
#endif

    
if(fd < 0)
    {
        free(
*dev_path);
        
if(id>0)
        {
            sprintf(buf,
"/dev/dsp%d",id);
            
if(!(*dev_path = strdup(buf)))
                
return -1;
        }
        
else
        {
            
if(!(*dev_path = strdup("/dev/dsp")))
                
return -1;
        }
#ifdef BROKEN_OSS
        fd 
= open(*dev_path, O_WRONLY | O_NONBLOCK);
#else
        fd 
= open(*dev_path, O_WRONLY);
#endif
    }

#ifdef BROKEN_OSS
    
if(fd >= 0 && blocking)
    {
        
if(fcntl(fd, F_SETFL, 0< 0)
        {
            close(fd);
            fd 
= -1;
        }
    }
#endif
    
if(fd < 0)
    {
        free(
*dev_path);
        
*dev_path = NULL;
    }
    
return fd;
}

只是在的我的ubuntu13.0.4下执行执行 ./text music.wav 会提示错误 返回-1 提示 no such directory
在网上搜有人说需要加载snd_pcm_oss
modprobe snd_pcm_oss
可我加载的时候提示
FATAL: Module snd_pcm_oss not found.
谁知道这个如何弄?

另外查了下可以加载alsa-oss
之后调用aoss ./text music.wav来播放音乐
可以这个不是我要的,非命令行下不能加这个前缀
posted @ 2013-07-19 22:11 ccsdu2009 阅读(1600) | 评论 (0)编辑 收藏
 
gaudio是一个基于C/C++混合编程的跨平台音频库,当前支持windows32操作系统和linux32位操作系统

修改记录
1.2013.04.01
    初次发布
2.2013.04.10
    完成对wav格式采样频率8000-48000,采样格式4,8,16,24,32的支持     
3.2013.05.01
    a.版本提升为1.4.0.8
    b.修改一个退出异常
    c.支持二源混音
    d.使用载入插件的方式提供对wav播放的支持
    e.增加对au格式的支持
    f.增加echo音效
    g.增加bassboost音效
    h.增加函数gaudio_address_get
    i.增加使用例子:echo/mixer/stream/boost
    j.把设置,获取音源三维空间信息的函数调整为: gaudio_source_set_float3,gaudio_source_get_float3
    k.修改解码器结构为回调模式
4.2013.05.10
    a.版本提升为1.6.8.0
    b.优化部分代码
    c.增加speedchanger音效
    d.增加音频翻转(g168)
    e.增加音频声道交换(g168)
    f.增加声道合并(g168)
    g.增加speedchanger/invert测试用例
    h.增加vc调用静态链接库libgaudio.lib
    i.增加调制音效和测试例子
    j.修改解码器框架
    k.修改获取音频采样编码格式不正确的问题
    l.解决seek定位不准的问题
    m.增加音效链测试例子
    n.增加函数gaudio_set_long,gaudio_get_long
    o.修改stream例子
    p.支持压缩mpc音频格式
    q.支持ogg/vorbis格式
    r.修改获取采样格式错误的bug
    t.增加接口说明文档    
5.2013.06.10
    a.版本提升为1.7.2.0
    b.gaudio_source_set_error_callback回调函数增加音源参数
    c.gaudio_source_set_finish_callback回调函数增加音源参数
    d.移除gaudio_get_version函数
    e.gaudio_effect_setcallback函数调整为gaudio_effect_set_callback
    f.使用插件式的音频驱动模式 - gwinmm
    g.gaudio代码优化
    h.增加音频源码率的获取
    i.增加feature范例
    j.完善文档
    k.增加对mp3的支持
    l.移除invert/modulator/bassboost例子
    m.增加balance
6.2013.07.07
    a.版本提升到1.8.0.2
    b.增加对交换文件aiff的支持
    c.修改音频驱动插件实现
    d.增加移相器音效
    e.修改部分API接口使用的long为int32_t以方便移植
    f.增加code::blocks测试工程
    g.增加msvc2008测试工程
    h.增加函数接口gaudio_source_create_from_buffer2以播放raw音频数据
    i.把各个音效参数提到单独文件
    j.简化wav解码
    k.修改几处内存泄漏
    l.增加音频回录功能,输出格式MP2,MP3,APE,WV,AAC,WAV,AU,AIFF,VOC,CAF,OGG
    当前录制信息:16位音频,双声道,采样频率44100
    m.增加音频回录的例子recorder
    n.测试例子使用getopt和usage提示
    o.增加对tta格式的支持    
7.2013.07.28
    a.版本提升到1.9.8.6                   
    b.解决了wav,au,aiff播放进度不准的故障
    c.优化wav/au/aiff解码性能        
    d.增加distortion音效              
    e.增加foldback distortion音效       
    f.增加distortion音效使用例子       
    g.增加声音穿透力                      
    h.修改结构最大支持八声道             
    i.增加portaudio插件驱动(win32&linux)  
    j.完成g168,bassbost的liux版本     
    k.完成wav,au音频格式的linux版本      
    l.代码增加部分注释(未完成)            
    m.尝试性支持linux操作系统             
    n.支持midi/mid音乐格式             
    o.解决了mixer混音退出报错的问题
    p.skip id3v2    
8.2013.08.16
    a.版本提升到2.0.0.1                    
    b.变量宏增加AUDIO_ENUM前缀
    c.增加非标准插件gsndfile支持flac/ogg/au/wav/aiff/voc/caf/..基于(sndfile)
    d.改用mpg123解码mp3
    e.支持FFT频谱
9.2013.09.08
    a.版本提升到2.0.6.0
    b.修改CROSSFEED宏和相关    
    c.引入200号插件支持s3m/mod/it/xm音频格式
    d.整理测试用例
    e.增加autowah音效
    f.增加驱动检测
10.2015.12.10 版本2.2.1.0
支持常见音频格式和音效,使用超级方便
下载在这里:/Files/gaimor/gaudio-sdk-2.2.1.0.zip

    
 
posted @ 2013-07-11 22:49 ccsdu2009 阅读(6550) | 评论 (2)编辑 收藏
 
#include <stdio.h>
#include 
<string.h>
#include 
<ao/ao.h>
#include 
<libmad/mad.h>
#include 
<math.h>
#include 
<limits.h>

signed 
short to_short(mad_fixed_t fixed)
{
    
if(fixed>=MAD_F_ONE)
        
return(SHRT_MAX);
    
if(fixed<=-MAD_F_ONE)
        
return(-SHRT_MAX);
    
fixed=fixed>>(MAD_F_FRACBITS-15);
    
return((signed short)fixed);
}

unsigned 
char inputBuffer[4096 + MAD_BUFFER_GUARD];

class libMP3
{
public:
    libMP3(
const char* filename)
    {   
        file 
= fopen(filename,"rb");
        mad_stream_init(
&stream);
        mad_frame_init(
&frame);    
        mad_synth_init(
&synth);
        mad_timer_reset(
&timer);            
    }
    
    
~libMP3()
    {
        mad_synth_finish(
&synth);
        mad_frame_finish(
&frame);
        mad_stream_finish(
&stream); 
        fclose(file);            
    }   
    
    
int setup()
    {
        size_t    remaining;
        unsigned 
char* read;

        
if(stream.next_frame!=NULL)
        {
           remaining
=stream.bufend-stream.next_frame;
           memmove(inputBuffer,stream.next_frame,remaining);
           read 
= inputBuffer+remaining;
           readsize 
= 4096-remaining;
        }
        
else
           readsize 
= 4096,
        read 
= inputBuffer,
        remaining
=0;

        readsize 
= fread(read,1,readsize,file);
        
if(readsize<=0)
        {

           return -1;
        }
        
        mad_stream_buffer(
&stream,inputBuffer,readsize+remaining);
        
char dest[100];
        mad_timer_string(timer, dest, 
"%02lu:%02u:%02u", MAD_UNITS_HOURS, MAD_UNITS_MILLISECONDS, 0);
        stream.error
=(mad_error)0;
        
return 0;        
    }
    
long readFrame(unsigned char* pcm)
    {
        
if(stream.buffer == NULL)
        {
           
if(setup() == -1
               
return -1;
        }
    
while(mad_frame_decode(&frame,&stream) != 0)
    {
        
if(MAD_RECOVERABLE(stream.error))
        {
            
if(stream.error!=MAD_ERROR_LOSTSYNC)
            {

            }
            
continue;
        }
        
else
            
if(stream.error==MAD_ERROR_BUFLEN)
            {

                if (setup() == -1return -1;
                
continue;
            }
            
else
            {
                
return -1;
            }
    }
    mad_synth_frame(
&synth,&frame);

    
//! 获取频率
    
//freq = synth.pcm.samplerate; 
    
    
//bitrate = frame.header.bitrate;
    
//channels = (frame.header.mode == MAD_MODE_SINGLE_CHANNEL) ? 1 : 2;
    
    mad_timer_add(
&timer,frame.header.duration);
    
int j = 0;
 
    
for(int i=0;i<synth.pcm.length;i++)
    {
        signed 
short    sample;
        sample
=to_short(synth.pcm.samples[0][i]);
        pcm[j
++= sample&0xff;
        pcm[j
++= sample>>8;
        
if(MAD_NCHANNELS(&frame.header)==2)
            sample
=to_short(synth.pcm.samples[1][i]);
        pcm[j
++= sample&0xff;
        pcm[j
++= sample>>8;
    }

    
char dest[120];
    mad_timer_string(timer,dest, 
"%lu:%02lu.%03u", MAD_UNITS_MINUTES, MAD_UNITS_MILLISECONDS, 0);
    
return j;        
    }
private:
    
struct mad_stream    stream;
    
struct mad_frame    frame;
    
struct mad_synth    synth;
    
struct mad_header   header;
    mad_timer_t            timer;    
    FILE
* file;            
    
long readsize;     
};

int main(int argc, char **argv)
{       
    
int rate = 44100;
    
int channels = 2;
 
    unsigned 
char data[4096];
    ao_device 
*device;
    ao_sample_format format;
    
int default_driver;
    ao_initialize();

    default_driver 
= ao_default_driver_id();
    memset(
&format,0,sizeof(format));
    format.bits 
= 16;
    format.channels 
= channels;
    format.rate 
= rate;
    format.byte_format 
= AO_FMT_LITTLE;
    
    libMP3 mp3(
"我只在乎你.mp3");
    
    device 
= ao_open_live(default_driver,&format,NULL);
    
if(device == NULL) 
    {
        fprintf(stderr,
"error opening device.\n");
        
return 1;
    }
    
    
long len = 0;
    unsigned 
char buffer[4096*2];
    
while(len = mp3.readFrame(buffer))
    {
        ao_play(device,(
char*)buffer,len);          
    }
   
    ao_close(device);
    ao_shutdown();
    
return (0);
}
posted @ 2013-06-09 21:14 ccsdu2009 阅读(1645) | 评论 (0)编辑 收藏
 
执行sudo alsa force-reload
重启电脑之后如果还不行执行

sudo apt-get remove --purge alsa-base pulseaudio

sudo apt-get install alsa-base pulseaudio

最后sudo alsa force-reload
posted @ 2013-06-07 19:48 ccsdu2009 阅读(700) | 评论 (0)编辑 收藏
 
gaudio是一个使用最方便的音频播放库
修改记录
1.2013.04.01
    初次发布
2.2013.04.10
    完成对wav格式采样频率8000-48000,采样格式4,8,16,24,32的支持     
3.2013.05.01
    a.版本提升为1.4.0.8
    b.修改一个退出异常
    c.支持二源混音
    d.使用载入插件的方式提供对wav播放的支持
    e.增加对au格式的支持
    f.增加echo音效
    g.增加bassboost音效
    h.增加函数gaudio_address_get
    i.增加使用例子:echo/mixer/stream/boost
    j.把设置,获取音源三维空间信息的函数调整为: gaudio_source_set_float3,gaudio_source_get_float3
    k.修改解码器结构为回调模式
4.2013.05.10
    a.版本提升为1.6.8.0
    b.优化部分代码
    c.增加speedchanger音效
    d.增加音频翻转(g168)
    e.增加音频声道交换(g168)
    f.增加声道合并(g168)
    g.增加speedchanger/invert测试用例
    h.增加vc调用静态链接库libgaudio.lib
    i.增加调制音效和测试例子
    j.修改解码器框架
    k.修改获取音频采样编码格式不正确的问题
    l.解决seek定位不准的问题
    m.增加音效链测试例子
    n.增加函数gaudio_set_long,gaudio_get_long
    o.修改stream例子
    p.支持压缩mpc音频格式
    q.支持ogg/vorbis格式
    r.修改获取采样格式错误的bug
    t.增加接口说明文档    
5.2013.06.01
    a.版本提升为1.7.2.0
    b.gaudio_source_set_error_callback回调函数增加音源参数
    c.gaudio_source_set_finish_callback回调函数增加音源参数
    d.移除gaudio_get_version函数
    e.gaudio_effect_setcallback函数调整为gaudio_effect_set_callback
    f.使用插件式的音频驱动模式(gwinmm)以方便支持linux和mac
    g.gaudio代码优化
    h.增加音频源码率的获取
    i.修改gfeature范例
    j.完善文档

readmap
1.格式:对mp3的支持
2.音效:立体声增强
3.处理故障/优化代码    

target
1.支持常见音频格式
2.支持常见音效
3.支持3D播放模式
4.最大支持3-8个音源同时播放
5.支持音频转换
6.支持录音
7.支持音频美化
8.跨平台   
posted @ 2013-06-02 12:41 ccsdu2009 阅读(614) | 评论 (1)编辑 收藏
 
#ifndef STREAM_BUFFER_H
#define STREAM_BUFFER_H
#include 
<stdio.h>
#include 
<stdlib.h>
#include 
"gaudio.h"

typedef 
struct _streamBuffer streamBuffer;
//typedef size_t(*streamRead)(void* ctx,void* ptr,size_t size,size_t nmemb);
//typedef int(*streamSeek)(void* ctx,glong offset,int flag);
//typedef int(*streamClose)(void* ctx);

streamBuffer
* stream_open_file(const gchar* file);
streamBuffer
* stream_open_mem(gvoid* mem,gulong size);
streamBuffer
* stream_open_callbacks(gread read,gseek seek,gtell tell,gclose close,gvoid* context);
glong         stream_read(streamBuffer
* stream,gvoid* ptr,gint size,glong nmemb);
glong         stream_seek(streamBuffer
* stream,glong offset,gint flag);
glong         stream_close(streamBuffer
* stream);

#endif
//! by ccsdu2004

#include <stdio.h>
#include 
<string.h>
#include 
"streamBuffer.h"
#include 
"gmemory.h"

struct _streamBuffer
{
    gread  read;
    gseek  seek;
    gclose close;
    gtell  tell;
    
void*  ctx;
};

typedef 
struct _stdIOContext
{
    FILE 
*fp;
}stdIOContext;

glong stdio_stream_read(gvoid
* ptr,gint size,glong nmemb,gvoid* ctx)
{
    
return fread(ptr,size,nmemb,((stdIOContext*)ctx)->fp);
}

glong stdio_stream_seek(gvoid
* ctx,glong offset,gint flag)
{
    
return fseek(((stdIOContext*)ctx)->fp,offset,flag);
}

glong APIENTRY stdio_stream_tell(gvoid
* ctx)
{
    
return ftell(((stdIOContext*)ctx)->fp);
}

glong stdio_stream_close(gvoid
* ptr)
{
    stdIOContext
* ctx = (stdIOContext*)ptr;
    gint ret 
= 0;
    ret 
= fclose(ctx->fp);
    gFreeBuffer(ctx);
    
return ret;
}

typedef 
struct memContext
{
    guchar
* base;
    guchar
* current;
    guchar
* end;
}memContext;

glong mem_stream_read(gvoid
* ptr,gint size,glong nmemb,gvoid* ctx)
{
    streamBuffer
* stream = (streamBuffer*)ctx;
    memContext 
*c;
    glong count;

    c 
= (memContext*)stream;
    count 
= nmemb;

    
if(c->current + count * size > c->end)
        count 
= (c->end - c->current) / size;

    memcpy(ptr, c
->current, count * size);
    c
->current += count * size;
    
return count;
}

glong mem_stream_seek(gvoid
* ctx,glong offset,gint flag)
{
    streamBuffer
* stream = (streamBuffer*)ctx;
    memContext
* c;
    c 
= (memContext*)stream;
    
if(c == NULL)
        
return -1;
    
if(flag == SEEK_SET)
    {
        
if(offset < 0 || offset > c->end - c->base)
            
return -1;
        c
->current = c->base + offset;
        
return 0;
    }
    
else if(flag == SEEK_CUR)
    {
        
if(offset > 0)
        {
            
if(offset > c->end - c->current)
                
return -1;
            c
->current += offset;
            
return 0;
        }
        
else if(offset < 0)
        {
            
if(-offset > c->current - c->base)
                
return -1;
            c
->current += offset;
            
return 0;
        }
    }
    
else if(flag == SEEK_END)
    {
        
if(offset > 0 || offset > c->end - c->base)
            
return -1;
        c
->current = c->end - offset;
        
return 0;
    }
    
return -1;
}

glong mem_stream_close(gvoid 
*ptr)
{
    memContext
* ctx = (memContext*)ptr;
    gFreeBuffer(ctx
->base);
    gFreeBuffer(ctx);
    
return 0;
}

streamBuffer
* stream_open_fp(FILE* fp)
{
    stdIOContext
* ctx;
    streamBuffer
* stream;

    stream 
= gcreate_buffer<streamBuffer>(1);
    
if(stream == NULL)
        
return NULL;

    ctx 
= gcreate_buffer<stdIOContext>(1);
    
if(ctx == NULL)
    {
        gFreeBuffer(stream);
        
return NULL;
    }

    ctx
->fp = fp;
    stream
->ctx = ctx;
    stream
->read = stdio_stream_read;
    stream
->seek = stdio_stream_seek;
    stream
->close = stdio_stream_close;
    
return stream;
}

streamBuffer
* stream_open_file(const gchar *file)
{
    FILE 
*fp;
    fp 
= fopen((char*)file,"rb");
    
if(fp == NULL)
       
return NULL;
    
return stream_open_fp(fp);
}

streamBuffer
* stream_open_mem(gvoid* mem,gulong size)
{
    memContext
*   ctx;
    streamBuffer
* stream;

    stream 
= gcreate_buffer<streamBuffer>(1);
    
if(stream == NULL)
        
return NULL;

    ctx 
= gcreate_buffer<memContext>(1);
    
if(ctx == NULL)
    {
        gFreeBuffer(stream);
        
return NULL;
    }

    ctx
->base = (guchar*)mem;
    ctx
->current = (guchar*)mem;
    ctx
->end = ((guchar*) mem) + size;

    stream
->ctx = ctx;
    stream
->read = mem_stream_read;
    stream
->seek = mem_stream_seek;
    stream
->close = mem_stream_close;

    
return stream;
}

streamBuffer
* stream_open_callbacks(gread read,gseek seek,gtell tell,gclose close,gvoid* context)
{
    streamBuffer
* stream = gcreate_buffer<streamBuffer>(1);
    
if(stream == NULL)
       
return NULL;

    stream
->ctx = context;
    stream
->read = read;
    stream
->seek = seek;
    stream
->tell = tell;
    stream
->close = close;
    
return stream;
}

glong stream_read(streamBuffer
* stream,gvoid* ptr,gint size,glong nmemb)
{
    
return stream->read(ptr,size,nmemb,stream->ctx);
}

glong stream_seek(streamBuffer
* stream,glong offset,gint flag)
{
    
return stream->seek(stream,offset,flag);
    
/*size_t c;
    char tmp[1024];
    while(offset > 0)
    {
        c = offset;
        if(c > 1024)
           c = 1024;
        offset -= c;

        if(c != stream_read(stream,tmp,1,c))
        {
        }
    }
    return 1;
*/
}

glong stream_close(streamBuffer
* stream)
{
    gint ret 
= stream->close(stream->ctx);
    gFreeBuffer(stream);
    
return ret;
}
posted @ 2013-04-09 20:56 ccsdu2009 阅读(575) | 评论 (0)编辑 收藏
 
     摘要: 这个也比较有用Code highlighting produced by Actipro CodeHighlighter (freeware)http://www.CodeHighlighter.com/-->#ifndef UI_TEST_H#define UI_TEST_H#include <QtCore/QVariant>#include ...  阅读全文
posted @ 2013-02-23 15:42 ccsdu2009 阅读(1113) | 评论 (0)编辑 收藏
 
#ifndef QTEST_H
#define QTEST_H
#include 
<QWidget>
#include 
<QState>
#include 
<QStateMachine>
#include 
"ui_test.h"

class QTest : public QWidget
{
    Q_OBJECT
public:
    QTest(QWidget 
*parent = 0, Qt::WFlags flags = 0);
    
~QTest();
private:
    UI ui;
    QStateMachine
* machine;
    QState
* state1;
    QState
* state2;
};

#endif
#include <QPropertyAnimation>
#include 
<QSignalTransition>
#include 
"qtest.h"
#include 
<iostream>

QTest::QTest(QWidget 
*parent, Qt::WFlags flags):QWidget(parent, flags)
{   
    machine 
= new QStateMachine(this);
    state1 
= new QState(machine); 
    state2 
= new QState(machine); 
    
    ui.setupUi(
this);

    QSize size(
300,280);
 
    
//state1->assignProperty(ui.groupBox,"size",size);
    state1->assignProperty(this,"size",QSize(313,224));
    
//state2->assignProperty(ui.groupBox,"size",QSize(size.width(),0));
    state2->assignProperty(this,"size",QSize(313,40));
    
//state2->assignProperty(ui.);
    
    
/*QPropertyAnimation* ani1 = new QPropertyAnimation(ui.groupBox,"size");  
    ani1->setDuration(800);    
    ani1->setEasingCurve(QEasingCurve::Linear); 
*/ 

    QPropertyAnimation
* ani2 = new QPropertyAnimation(this,"size");  
    ani2
->setDuration(1200);    
    ani2
->setEasingCurve(QEasingCurve::Linear); 
    
    QSignalTransition 
*transition1=state1->addTransition(ui.button,SIGNAL(clicked()),state2);
    
//transition1->addAnimation(ani1);  
    transition1->addAnimation(ani2);
    QSignalTransition 
*transition2=state2->addTransition(ui.button,SIGNAL(clicked()),state1);  
    
//transition2->addAnimation(ani1); 
    transition2->addAnimation(ani2);
    machine
->setInitialState(state1);
    machine
->start();      
}

QTest::
~QTest()
{
}

这个例子很实用
posted @ 2013-02-21 21:43 ccsdu2009 阅读(791) | 评论 (0)编辑 收藏
 
很简单:
    QPrinter printer(QPrinter::HighResolution);
    printer.setOutputFormat(QPrinter::PdfFormat);
    QString name = ui.line->text();
    printer.setOutputFileName(pdf);
    ui.text->document()->print(&printer);
很简单 不过貌似没有保存为doc文档的接口
posted @ 2013-02-10 20:13 ccsdu2009 阅读(861) | 评论 (0)编辑 收藏
 
To use the library to create WavPack files from raw PCM audio, the user must provide a WavpackBlockOutput function that is used by the library to write finished WavPack blocks to the output. Unlike the read case, there is no facility to write directly to named files. Here is the function required:

  typedef int (*WavpackBlockOutput)(void *id, void *data, int32_t bcount);

where the "id" is used to differentiate the regular WavPack data "wv" from the correction data "wvc" (or for the case of multiple streams running at the same time). The return value is simply TRUE for success and FALSE for error. An example of this function can be found in wavpack.c called write_block().

The basic procedure for creating WavPack files is this:

  1. get a context and set block output function with WavpackOpenFileOutput()
  2. set the data format and specify modes with WavpackSetConfiguration()
  3. optionally write a RIFF header with WavpackAddWrapper()
  4. allocate buffers and prepare for packing with WavpackPackInit()
  5. actually compress audio and write blocks with WavpackPackSamples()
  6. flush final samples into blocks with WavpackFlushSamples()
  7. optionally write MD5 sum with WavpackStoreMD5Sum()
  8. optionally write RIFF trailer with WavpackAddWrapper()
  9. if MD5 sum or RIFF trailer written, call WavpackFlushSamples() again
  10. optionally append metadata tag with functions in next section
  11. optionally update number of samples with WavpackUpdateNumSamples()
  12. close the context with WavpackCloseFile()

Note that this does not show opening and closing the output files which is done by the application itself.

  WavpackContext *WavpackOpenFileOutput (WavpackBlockOutput blockout,void *wv_id, void *wvc_id);
  -----------------------------------------------------------------

Open context for writing WavPack files. The returned context pointer is used in all following calls to the library. The "blockout" function will be used to store the actual completed WavPack blocks and will be called with the id pointers containing user defined data (one for the wv file and one for the wvc file). A return value of NULL indicates that memory could not be allocated for the context.

  int WavpackSetConfiguration (WavpackContext *wpc,WavpackConfig *config,uint32_t total_samples);
  ----------------------------------------------------

Set configuration for writing WavPack files. This must be done before sending any actual samples, however it is okay to send wrapper or other metadata before calling this. The "config" structure contains the following *required* information:

 config->bytes_per_sample     see WavpackGetBytesPerSample() for info
 config->bits_per_sample      see WavpackGetBitsPerSample() for info
 config->channel_mask         Microsoft standard (mono = 4, stereo = 3)
 config->num_channels         self evident
 config->sample_rate          self evident

Be particularly careful with the "channel_mask" field. If this is not set to the correct value (3 or 4) then everything will still appear to work
correctly, but the resulting WavPack file will have undefined channel assignments. When this file is unpacked back to WAV it will then get a
WAVEFORMATEXTENSIBLE header which some programs refuse to recognize.

Specifying these 5 parameters alone would create a default lossless WavPack file, identical to the one produced by using the command-line program without options. For optional configuration, the following fields and flags may be set:

 config->flags:
 --------------
 o CONFIG_HYBRID_FLAG         select hybrid mode (must set bitrate)
 o CONFIG_JOINT_STEREO        select joint stereo (must set override also)
 o CONFIG_JOINT_OVERRIDE      override default joint stereo selection
 o CONFIG_HYBRID_SHAPE        select hybrid noise shaping (set override & shaping_weight != 0.0)
 o CONFIG_SHAPE_OVERRIDE      override default hybrid noise shaping (set CONFIG_HYBRID_SHAPE and shaping_weight)
 o CONFIG_DYNAMIC_SHAPING     force dynamic noise shaping even when WavPack
                               would not use it (no need to set any of the
                               other shaping flags when using this one)
 o CONFIG_FAST_FLAG           "fast" compression mode (same as -f)
 o CONFIG_HIGH_FLAG           "high" compression mode (same as -h)
 o CONFIG_VERY_HIGH_FLAG      "very high" compression mode (same as -hh)
 o CONFIG_BITRATE_KBPS        hybrid bitrate is kbps, not bits / sample
 o CONFIG_CREATE_WVC          create correction file
 o CONFIG_OPTIMIZE_WVC        maximize bybrid compression (same as -cc)
 o CONFIG_CALC_NOISE          calc noise in hybrid mode
 o CONFIG_EXTRA_MODE          extra processing mode (same as -x)
 o CONFIG_SKIP_WVX            no wvx stream for floats & large ints (same as -p)
 o CONFIG_MD5_CHECKSUM        specify if you plan to store MD5 signature (the sum is calculated by the application, NOT by the library)
 o CONFIG_CREATE_EXE          specify if you plan to prepend sfx module
 o CONFIG_OPTIMIZE_MONO       detect and optimize for mono files posing as
                               stereo (uses a more recent stream format that
                               is not compatible with decoders < 4.3)

 config->bitrate              hybrid bitrate in either bits/sample or kbps
 config->shaping_weight       hybrid noise shaping coefficient override
 config->block_samples        force samples per WavPack block (0 = use default, else 1-131072)
 config->float_norm_exp       select floating-point data (127 for +/-1.0)
 config->xmode                extra mode processing value override (1-6)

If the number of samples to be written is known then it should be passed here.
If the duration is not known then pass -1. In the case that the size is not
known (or the writing is terminated early) then it is suggested that the
application retrieve the first block written and let the library update the
total samples indication. A function is provided to do this update and it
should be done to the "correction" file also. If this cannot be done (because
a pipe is being used, for instance) then a valid WavPack will still be created
(assuming the initial duration was set to -1), but when applications want to
access that file they will have to seek all the way to the end to determine the
actual duration (the library takes care of this). Also, if a RIFF header has
been included then it should be updated as well or the WavPack file will not be
directly unpackable to a valid wav file (although it will still be usable by
itself). A return of FALSE indicates an error (use WavpackGetErrorMessage() to
find out what happened).

  int WavpackPackInit (WavpackContext *wpc);
  -----------------------------------------

Prepare to actually pack samples by determining the size of the WavPack blocks
and allocating sample buffers and initializing each stream. Call after
WavpackSetConfiguration() and before WavpackPackSamples(). A return of FALSE
indicates an error.

  int WavpackPackSamples (WavpackContext *wpc,
                          int32_t *sample_buffer,
                          uint32_t sample_count);
  ----------------------------------------------

Pack the specified samples. Samples must be stored in 32-bit longs in the
native endian format of the executing processor. The number of samples specified
indicates composite samples (sometimes called "frames"). So, the actual number
of data points would be this "sample_count" times the number of channels. Note
that samples are accumulated here until enough exist to create a complete
WavPack block (or several blocks for multichannel audio). If an application
wants to break a block at a specific sample, then it just calls
WavpackFlushSamples() to force an early termination. Completed WavPack blocks
are sent to the function provided in the initial call to
WavpackOpenFileOutput(). A return of FALSE indicates an error (which most likely
indicates the that user-supplied blockout function returned an error).

  int WavpackFlushSamples (WavpackContext *wpc);
  ---------------------------------------------

Flush all accumulated samples into WavPack blocks. This is normally called after
all samples have been sent to WavpackPackSamples(), but can also be called to
terminate a WavPack block at a specific sample (in other words it is possible
to continue after this operation). This also must be called to dump non-audio
blocks like those holding metadata for MD5 sums or RIFF trailers. A return of
FALSE indicates an error.

  void WavpackUpdateNumSamples (WavpackContext *wpc, void *first_block);
  ---------------------------------------------------------------------

Given the pointer to the first block written (to either a .wv or .wvc file),
update the block with the actual number of samples written. If the wav header
was generated by the library, then it is updated also. This should be done if
WavpackSetConfiguration() was called with an incorrect number of samples (or
-1). This should also be done in the case where the application did not provide
the RIFF header but did add some chunks for a RIFF trailer (see the section
on adding RIFF metadata). It is the responsibility of the application to read
and rewrite the block. An example of this can be found in the Audition filter
or in the command-line packer when the -i option is used. ON MACHINES WITH
ALIGNMENT REQUIREMENTS, BE SURE THAT THE PASSED POINTER IS PROPERLY ALIGNED!

  int WavpackStoreMD5Sum (WavpackContext *wpc, uchar data [16]);
  -------------------------------------------------------------

Store computed MD5 sum in WavPack metadata. Note that the user must compute the
16 byte sum; it is not done here. It is also required that WavpackFlushSamples()
be called after this to make sure the block containing the MD5 sum is actually
written. A return of FALSE indicates an error.

  WavpackContext *WavpackCloseFile (WavpackContext *wpc);
  ------------------------------------------------------

Close the specified WavPack file and release all resources used by it.
Returns NULL.


With respect to the RIFF WAV wrapper that is inormally appended to the WavPack
file, there are three options available for the application to handle this.

The first is the simplest, and that is for the application to simply do
nothing. The library will automatically create a RIFF header appropriate for
the audio data (including WAVEFORMATEXTENSIBLE if needed) and store this
in the WavPack file. If the application does not know the actual number of
samples beforehand and needs to reread the first block and have the library
update it, then the library will handle updating its own RIFF header also.
In this scenario, there will be no trailing RIFF data. For the vast majority
of applications, this will be all that is required.

However, some applications may want to store a custom RIFF header (and trailer)
so that they can store extra RIFF chunks in there or perhaps they want to
create an exact copy of a .wav file (like the WavPack command-line program
does). To accomplish this, functions are provided (see below) to add RIFF
metadata to a WavPack file being written. In this case, the application must
provide a verbatim copy of all the RIFF data from the initial "RIFF" at the
beginning of the file up to (and including) the size field of the "data"
chunk. If any trailing RIFF data is desired, then this is appended after all
samples have been packed and flushed. This wrapper data will be *exactly*
what wvunpack will use to restore an original WAV file. In no circumstances
does the WavPack library parse, verify, or otherwise use this data.

If the RIFF header information needs to be updated after packing (because the
total file size or the data chunk size need to be update) then the first
block must be reread and the function WavpackGetWrapperLocation() must be
called to find the wrapper in the block (it would be possible to find it by
searching for the "RIFF", but using this function is significantly less ugly).
The WavPack library will not touch a wrapper that it did not create when
calling WavpackUpdateNumSamples().

The third option for including RIFF data chunks is a hybrid between these
two methods and is useful if an application wants to add a few specific RIFF
chunks and does not mind if the chunks appear at the end of the WAV file. In
this method, the application does not send any RIFF header before packing the
audio data which forces the library to create and store a standard RIFF header.
However, when all samples have been packed, the application sends the RIFF
chunks that it wants to add at the end of the file (RIFF trailer). Then, after
flushing, it must reread the first block and call WavpackUpdateNumSamples() so
that the library can update the RIFF header to reflect the added chunks (even
if the number of samples was correct). Because the library created the header,
it will update it, and will take into account the RIFF chunks added to the end.

All of this wrapper stuff can be a little confusing. It is a good idea to
test that the final application is working correctly and creating WavPack
files that will unpack to valid WAV files (even if the RIFF info is totally
wrong, the files will still work perfectly well as WavPack files because,
again, the RIFF wrapper is just informational). The first test is to use the
-ss option on WvUnpack to make sure the RIFF wrapper is reported correctly.
Then, unpack the WavPack file into a WAV using WvUnpack and repack it again
with the standard WavPack command-line program (without options). If it
doesn't complain about anything then there is a good chance that all the
wrapper information is valid.

Here are the appropriate functions:

  int WavpackAddWrapper (WavpackContext *wpc, void *data, uint32_t bcount);
  ------------------------------------------------------------------------

Add wrapper (currently RIFF only) to WavPack blocks. This should be called
before sending any audio samples in the case of the RIFF header or after all
samples have been sent (and flushed) for any RIFF trailer. It is also
required that WavpackFlushSamples() be called again after specifying a RIFF
trailer to make sure it is actually written to the file.

If the exact contents of the RIFF header are not known because, for example,
the file duration is uncertain or trailing chunks are possible, simply write
a "dummy" header of the correct length. When all data has been written it
will be possible to read the first block written and update the header
directly. An example of this can be found in the Audition filter. A return of
FALSE indicates an error.

  void *WavpackGetWrapperLocation (void *first_block, uint32_t *size);
  -------------------------------------------------------------------

Given the pointer to the first block written to a WavPack file, this function
returns the location of the stored RIFF header that was originally written with
WavpackAddWrapper(). This would normally be used to update the wav header to
indicate that a different number of samples was actually written or if
additional RIFF chunks are written at the end of the file. The "size" parameter
can be set to non-NULL to obtain the exact size of the RIFF header, and the
function will return FALSE if the header is not found in the block's metadata
(or it is not a valid WavPack block). Note that the size of the RIFF header
cannot be changed and it is the responsibility of the application to read and
rewrite the block. An example of this can be found in the Audition filter.


******************************************************************************
*************************   5.0 TAGGING FUNCTIONS   **************************
******************************************************************************

The WavPack library contains rudimentary support to read and write metadata tags
on WavPack files. This includes creating new APEv2 tags during WavPack file
creation, reading text fields from both ID3v1 and APEv2 tags on existing
WavPack files, and editing data in APEv2 tags.

Users should be aware of the following limitations of this functionality:

1. ID3v1 tags are read-only, and cannot be accessed if there is an APEv2 tag
   prior to them in the file. ID3v1 tags are lost if the prior APEv2 tag is
   edited.

2. The text items in APEv2 tags are UTF-8 encoded. The functionality of
   converting to/from any local or multi-byte encoding must be handled by the
   calling application.

3. The binary items of APEv2 tags can now (version 4.60+) be read and written.
   To implement this in a backward-compatible way, the existing functions for
   accessing text tag items were simply duplicated as versions handling only
   binary tags items. The versions for text tag items work exactly as before
   (ignoring binary items) and the binary versions ignore text items.

   The convention for binary tag items in APEv2 tags is that the data starts
   with a NULL-terminated string representing a filename. After the terminating
   NULL, the actual binary data starts. In the WavPack code this filename has
   only the extension of the actual file; the name portion is made up of the
   tag item name. NOTE THAT THIS FUNCTIONALITY IS NOT HANDLED IN THE LIBRARY.
   THE LIBRARY ONLY STORES AND RETRIEVES A BINARY IMAGE AND IT IS UP TO THE
   CALLING APPLICATION TO APPEND AND HANDLE THIS FILENAME.

4. When APEv2 tags are edited and the resulting tags are shorter than the
   original tags, the tag is padded with zeros at the front rather than having
   the file shortened, and this padding cannot be reclaimed by future editing.
   The net result of this is that repeated editing of tags will cause the file
   to grow indefinitely (although this will only happen when the tag is
   actually made smaller).

In these descriptions the meaning of the word "tag" refers to the whole bundle
that is appended to the end of the WavPack file. This bundle may contain many
individual items, each consisting of a key/value pair. The key is referred to
here as the "item", meaning the item's name (like "artist"). Some people refer
to the individual items as "tags", but that usage is not used here. Also note
that APEv2 tags store the case of tag item names and values, but are not case
sensitive when locating tag item names (and this is carried here into the
lookup of ID3v1 tag item names).


  int WavpackGetNumTagItems (WavpackContext *wpc);
  int WavpackGetNumBinaryTagItems (WavpackContext *wpc);
  ------------------------------------------------------

Count and return the total number of tag items (either text or binary) in the
specified file. This works with either ID3v1 tags or APEv2 tags (although ID3V1
tags do not have binary items).

  int WavpackGetTagItem (WavpackContext *wpc,
                         const char *item,
                         char *value,
                         int size);

  int WavpackGetBinaryTagItem (WavpackContext *wpc,
                               const char *item,
                               char *value,
                               int size)
  ------------------------------------------------------------

Attempt to get the specified item from the specified file's ID3v1 or APEv2 tag.
The "size" parameter specifies the amount of space available at "value", if the
desired text item will not fit in this space then ellipses (...) will be
appended and the string terminated (binary tag data is simply truncated). The
actual length of the string (or binary data) is returned (or 0 if no matching
value found). Note that with APEv2 text tags the length might not be the same
as the number of characters because UTF-8 encoding is used. Also, APEv2 text
tags can have multiple (NULL separated) strings for a single value (this is why
the length is returned). If this function is called with a NULL "value" pointer
(or a zero "length") then only the actual length of the value data is returned
(not counting the terminating NULL of text tag items). This can be used to
determine the actual memory to be allocated beforehand.

For ID3v1 tags the only "item" names supported are "title", "artist", "album",
"year", "comment" and "track" (which is converted to numeric text by the
library).

  int WavpackGetTagItemIndexed (WavpackContext *wpc,
                                int index,
                                char *item,
                                int size);

  int WavpackGetBinaryTagItemIndexed (WavpackContext *wpc,
                                      int index,
                                      char *item,
                                      int size);
  -------------------------------------------------

This function looks up the tag item name by index and is used when the
application wants to access all the items in the file's ID3v1 or APEv2 tag.
Note that this function accesses only the item's name; WavpackGetTagItem()
still must be called to get the actual value. The "size" parameter specifies
the amount of space available at "item", if the desired item will not fit in
this space then ellipses (...) will be appended and the string terminated.
The actual length of the string is returned (or 0 if no item exists for index).
If this function is called with a NULL "value" pointer (or a zero "length")
then only the actual length of the item name is returned (not counting the
terminating NULL). This can be used to determine the actual memory to be
allocated beforehand.

  int WavpackAppendTagItem (WavpackContext *wpc,
                            const char *item,
                            const char *value,
                            int vsize);

  int WavpackAppendBinaryTagItem (WavpackContext *wpc,
                                  const char *item,
                                  const char *value,
                                  int vsize);
  ---------------------------------------------

This function is used to append (or replace) the specified field to the tag
being created or edited. If no tag has been started, then an empty one will be
allocated first. When finished adding all the items to the tag, use
WavpackWriteTag() to write the completed tag to the file. Note that ID3 tags
are not supported. A size parameter is included so that text values containing
multiple (NULL separated) strings (and binary data) can be written. A FALSE
return indicates an error.

  int WavpackDeleteTagItem (WavpackContext *wpc, const char *item);
  ----------------------------------------------------------------

Delete the specified tag item from the APEv2 tag being created or edited. This
function works with either text or binary fields. Returns TRUE to indicate that
an item was actually deleted from the tag.

  int WavpackWriteTag (WavpackContext *wpc);
  -----------------------------------------

Once a APEv2 tag has been created (or edited) using WavpackAppendTagItem()
(and WavpackDeleteTagItem()), this function is used to write the completed tag
to the end of the WavPack file. Note that this is NOT done for EACH item in the
tag, but only after ALL items have been added to the tag.

If this function is called when creating a WavPack file, then it uses the same
"blockout" function that is used to write regular WavPack blocks (and should be
called after flushing all the audio data and writing any WavPack metadata like
RIFF trailers and MD5 sums). It may call the blockout function multiple times
to write the tag.

If this function is called when editing an existing APEv2 tag, then it will
seek to the correct position and write the tag using the WavpackStreamReader
function that has been added for this purpose (write_bytes) or using its
own standard I/O functions (if the WavpackStreamReader is not being used).
Because there is not currently a method implemented to truncate an existing
file to a shorter length, this function will pad the file with 0's in front
of a tag that had been edited to a shorter length.


******************************************************************************
**********************   6.0 HANDLING WAVPACK STREAMS   **********************
******************************************************************************

In some applications (for example streaming applications and some filters, or
cases where WavPack data might be embedded into another multimedia container)
it is required for the audio file parsing functions to be separated from the
decoding functions. This is accomplished in two steps with the WavPack library.

First, the parsing functions are implemented outside the WavPack library. It is
very straightforward to parse WavPack files because the WavPack block header is
easy to recognize, and contains easy to parse and interpret information about
the block's contents and its relation to the whole WavPack file (or stream). The
exact file and block formats are described in detail in the file_format.txt
document. The wputils.c module also contains helper functions and a useful
seeking function that may also be useful in creating a WavPack parser.

Next, the individual parsed blocks are decoded to PCM audio by the library. To
accomplish this a "file" is opened with WavpackOpenFileInputEx() where the
specified WavpackStreamReader is a function that will feed the raw WavPack
block's bytes into the library when requested. The flags parameter should have
the OPEN_STREAMING bit set so that the decoder will ignore the position and any
other "whole file" information in the block headers. The decoder will suck up
the first block (through the stream reader) that actually contains audio and
stop, ready to decode. The next step is to call WavpackUnpackSamples() to
unpack the actual number of samples in the block (which should be known by the
parser).

Normally, the entire block would be unpacked and then the decoder would be
ready for the next block. If a single additional sample is requested past the
size of the current block the decoder will attempt to read the next block, so
it is important to request the exact number of samples (unless this behavior is
okay). If it is not desired to finish decoding the block then there are two
options. The easiest would be to simply decode the rest of the block anyway and
discard the results. Another option would be to close the context with the
function WavpackCloseFile() and then open another context when needed.

This procedure will also work fine for multichannel WavPack files. The decoder
will have to suck up all the blocks for the various channels before decoding may
begin.


******************************************************************************
**************************   7.0 ZIP FORMAT USAGE   **************************
******************************************************************************

With version 11.0, WinZip Computing has added WavPack Audio to the official ZIP
file format standard as compression method 97, as described here:

    http://www.winzip.com/ppmd_info.htm

The WavPack library can easily be used to create or decode the WavPack images
stored in the ZIP files. Some issues to keep in mind:

1. Only lossless mode is used. WinZip's implementation uses the "very high"
   mode with no extra processing, although there is no reason that a different
   profile could not be employed as they would still be fully compatible (for
   example, the new "high" mode and/or the new "extra" mode could be used).

2. All bitdepths (including 32-bit floating-point) are supported. However,
   bitdepths that are not multiples of 8 should be rounded up to the next
   multiple of 8 to ensure that all samples (even illegal ones) are encoded
   losslessly (this is described in more detail in the WinZip document).

3. Multichannel data (with or without WAVEFORMATEXTENSIBLE) is fully supported.

4. CONFIG_OPTIMIZE_MONO is not available during decoding and therefore should
   not be used for encoding.

5. The WavPack data must have RIFF headers (to generate .wav files) and may
   optionally have RIFF trailers. It would not be appropriate to have WavPack
   generate the RIFF headers (either during encode or decode) because of the
   obvious danger of generating files that don't match exactly.

6. The WavPack data should probably NOT have metadata tags or MD5 sums added
   to it. This information would be discarded during decoding anyway and could
   possibly trigger an error condition in a decoder.

The easiest way of using the WavPack library to decode the embedded WavPack
data would be to open a WavPack context using WavpackOpenFileInputEx() and
provide a WavpackStreamReader that would read the appropriate part of the
ZIP file by using an offset. If only the standard unpacking operations are
used, then the WavPack library will not attempt to seek during a decode. The
only flag to use for the "open" call would be OPEN_WRAPPER.

The most critical aspect of creating WavPack images to embed in ZIP files is
making sure that the decoded data will exactly match the source. This is in
contrast to the case of WavPack command-line programs where some invalid WAV
files may not encode (or exactly decode) for one reason or another. For this
reason it is important to check the parameters in the WAV header carefully and
allow only a well-defined set of known good combinations. The size of the audio
data should be checked to make sure it contains the correct number of whole
composite samples (or if it doesn't then this is properly handled). Since
WavPack cannot properly decode WavPack files that contain no audio data (i.e.
zero samples), this case should also be avoided. In all situations where some
question exists, the prudent choice would be to default to some other (more
genereralized) data compression method.
posted @ 2013-02-09 18:57 ccsdu2009 阅读(935) | 评论 (0)编辑 收藏
仅列出标题
共38页: First 9 10 11 12 13 14 15 16 17 Last