| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 7005 人关注过本帖
标题:###### 再发一个更好玩的东西 ######
只看楼主 加入收藏
yanjiali
该用户已被删除
收藏
得分:2 
提示: 作者被禁止或删除 内容自动屏蔽
2010-05-17 21:15
小耗子
Rank: 2
等 级:论坛游民
帖 子:18
专家分:25
注 册:2010-5-12
收藏
得分:2 
弱弱的问下 这个是3d的吗
2010-05-17 21:29
wycstc100
Rank: 1
等 级:新手上路
帖 子:5
专家分:4
注 册:2010-5-11
收藏
得分:2 
有没有代码啊。。
跪求代码。。。。
2010-05-17 22:50
rtgirl
该用户已被删除
收藏
得分:0 
提示: 作者被禁止或删除 内容自动屏蔽
2010-05-17 23:05
StarWing83
Rank: 8Rank: 8
来 自:仙女座大星云
等 级:贵宾
威 望:19
帖 子:3951
专家分:748
注 册:2007-11-16
收藏
得分:0 
= =网格上面应用胡克定律………………参数不好调啊= =

写个试试看……不保证能写出来= =

专心编程………
飞燕算法初级群:3996098
我的Blog
2010-05-17 23:22
lijm1989
Rank: 11Rank: 11Rank: 11Rank: 11
来 自:珠海
等 级:贵宾
威 望:12
帖 子:675
专家分:2844
注 册:2009-10-14
收藏
得分:0 
现在服了~~~期待再一次好玩的东东~~~~
2010-05-17 23:28
StarWing83
Rank: 8Rank: 8
来 自:仙女座大星云
等 级:贵宾
威 望:19
帖 子:3951
专家分:748
注 册:2007-11-16
收藏
得分:0 
不对……我怎么觉得这个看上去像网上很流行的水波动画……我搜搜再说…………

专心编程………
飞燕算法初级群:3996098
我的Blog
2010-05-17 23:39
pgy
Rank: 11Rank: 11Rank: 11Rank: 11
来 自:C
等 级:小飞侠
威 望:8
帖 子:1248
专家分:2329
注 册:2009-9-23
收藏
得分:0 
程序代码:
Appendix: wave.c example
This is a sample application that plays back audio data: 

#include <errno.h>
#include <fcntl.h>
#include <gulliver.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/ioctl.h>
#include <sys/select.h>
#include <sys/stat.h>
#include <sys/termio.h>
#include <sys/types.h>
#include <unistd.h>

#include <sys/asoundlib.h>


const char *kRiffId = "RIFF";
const char *kWaveId = "WAVE";

typedef struct
{
    char    tag[4];
    long    length;
}
RiffTag;

typedef struct
{
    char    Riff[4];
    long    Size;
    char    Wave[4];
}
RiffHdr;


typedef struct
{
    short   FormatTag;
    short   Channels;
    long    SamplesPerSec;
    long    AvgBytesPerSec;
    short   BlockAlign;
    short   BitsPerSample;
}
WaveHdr;


int
err (char *msg)
{
    perror (msg);
    return -1;
}


int
FindTag (FILE * fp, const char *tag)
{
    int     retVal;
    RiffTag tagBfr =
    {"", 0};

    retVal = 0;

    // Keep reading until we find the tag or hit the EOF.
    while (fread ((unsigned char *) &tagBfr, sizeof (tagBfr), 1, fp))
    {

        // If this is our tag, set the length and break.   
        if (strncmp (tag, tagBfr.tag, sizeof tagBfr.tag) == 0)
        {
            retVal = ENDIAN_LE32(tagBfr.length);
            break;
        }

        // Skip ahead the specified number of bytes in the stream          
        fseek (fp, tagBfr.length, SEEK_CUR);
    }

    // Return the result of our operation
    return (retVal);
}


int
CheckHdr (FILE * fp)
{
    RiffHdr riffHdr =
    {"", 0};

    // Read the header and, if successful, play the file
    // file or WAVE file.
    if (fread ((unsigned char *) &riffHdr, sizeof (RiffHdr), 1, fp) == 0)
        return 0;

    if (strncmp (riffHdr.Riff, kRiffId, strlen (kRiffId)) ||
        strncmp (riffHdr.Wave, kWaveId, strlen (kWaveId)))
        return -1;

    return 0;
}


int
dev_raw (int fd)
{
    struct termios termios_p;

    if (tcgetattr (fd, &termios_p))
        return (-1);

    termios_p.c_cc[VMIN] = 1;
    termios_p.c_cc[VTIME] = 0;
    termios_p.c_lflag &= ~(ECHO | ICANON | ISIG |
        ECHOE | ECHOK | ECHONL);
    termios_p.c_oflag &= ~(OPOST);
    return (tcsetattr (fd, TCSANOW, &termios_p));
}

int
dev_unraw (int fd)
{
    struct termios termios_p;

    if (tcgetattr (fd, &termios_p))
        return (-1);

    termios_p.c_lflag |= (ECHO | ICANON | ISIG |
        ECHOE | ECHOK | ECHONL);
    termios_p.c_oflag |= (OPOST);
    return (tcsetattr (fd, TCSAFLUSH, &termios_p));
}


//*****************************************************************************
/* *INDENT-OFF* */
#ifdef __USAGE
%C[Options] *

Options:
    -a[card#:]<dev#>  the card & device number to play out on
#endif
/* *INDENT-ON* */
//*****************************************************************************


int
main (int argc, char **argv)
{
    int     card = -1;
    int     dev = 0;
    snd_pcm_t *pcm_handle;
    FILE   *file1;
    WaveHdr wavHdr1;
    int     mSamples;
    int     mSampleRate;
    int     mSampleChannels;
    int     mSampleBits;
    char   *mSampleBfr1;

    int     rtn;
    snd_pcm_channel_info_t pi;
    snd_mixer_t *mixer_handle;
    snd_mixer_group_t group;
    snd_pcm_channel_params_t pp;
    snd_pcm_channel_setup_t setup;
    int     bsize, n, N = 0, c;
    fd_set  rfds, wfds;


    while ((c = getopt (argc, argv, "a:")) != EOF)
    {
        switch (c)
        {
        case 'a':
            if (strchr (optarg, ':'))
            {
                card = atoi (optarg);
                dev = atoi (strchr (optarg, ':') + 1);
            }
            else
                dev = atoi (optarg);
            printf ("Using card %d device %d \n", card, dev);
            break;
        default:
            return 1;
        }
    }

    setvbuf (stdin, NULL, _IONBF, 0);
    if (card == -1)
    {
        if ((rtn = snd_pcm_open_preferred (&pcm_handle, &card, &dev, SND_PCM_OPEN_PLAYBACK)) < 0)
            return err ("device open");
    }
    else
    {
        if ((rtn = snd_pcm_open (&pcm_handle, card, dev, SND_PCM_OPEN_PLAYBACK)) < 0)
            return err ("device open");
    }

    if (argc < 2)
        return err ("no file specified");

    if ((file1 = fopen (argv[optind], "r")) == 0)
        return err ("file open #1");

    if (CheckHdr (file1) == -1)
        return err ("CheckHdr #1");

    mSamples = FindTag (file1, "fmt ");
    fread (&wavHdr1, sizeof (wavHdr1), 1, file1);
    fseek (file1, (mSamples - sizeof (WaveHdr)), SEEK_CUR);

    mSampleRate = ENDIAN_LE32(wavHdr1.SamplesPerSec);
    mSampleChannels = ENDIAN_LE16(wavHdr1.Channels);
    mSampleBits = ENDIAN_LE16(wavHdr1.BitsPerSample);

    printf ("SampleRate = %d, Channels = %d, SampleBits = %d\n", mSampleRate, mSampleChannels, mSampleBits);

    /* disabling mmap is not actually required in this example but it is included to
     * demonstrate how it is used when it is required.
     */
    if ((rtn = snd_pcm_plugin_set_disable (pcm_handle, PLUGIN_DISABLE_MMAP)) < 0)
    {
        fprintf (stderr, "snd_pcm_plugin_set_disable failed: %s\n", snd_strerror (rtn));
        return -1;
    }

    memset (&pi, 0, sizeof (pi));
    pi.channel = SND_PCM_CHANNEL_PLAYBACK;
    if ((rtn = snd_pcm_plugin_info (pcm_handle, &pi)) < 0)
    {
        fprintf (stderr, "snd_pcm_plugin_info failed: %s\n", snd_strerror (rtn));
        return -1;
    }

    memset (&pp, 0, sizeof (pp));

    pp.mode = SND_PCM_MODE_BLOCK;
    pp.channel = SND_PCM_CHANNEL_PLAYBACK;
    pp.start_mode = SND_PCM_START_FULL;
    pp.stop_mode = SND_PCM_STOP_STOP;

    pp.buf.block.frag_size = pi.max_fragment_size;
    pp.buf.block.frags_max = 1;
    pp.buf.block.frags_min = 1;

    pp.format.interleave = 1;
    pp.format.rate = mSampleRate;
    pp.format.voices = mSampleChannels;

    if (mSampleBits == 8)
        pp.format.format = SND_PCM_SFMT_U8;
    else
        pp.format.format = SND_PCM_SFMT_S16_LE;

    if ((rtn = snd_pcm_plugin_params (pcm_handle, &pp)) < 0)
    {
        fprintf (stderr, "snd_pcm_plugin_params failed: %s\n", snd_strerror (rtn));
        return -1;
    }

    if ((rtn = snd_pcm_plugin_prepare (pcm_handle, SND_PCM_CHANNEL_PLAYBACK)) < 0)
        fprintf (stderr, "snd_pcm_plugin_prepare failed: %s\n", snd_strerror (rtn));


    memset (&setup, 0, sizeof (setup));
    memset (&group, 0, sizeof (group));
    setup.channel = SND_PCM_CHANNEL_PLAYBACK;
    setup.mixer_gid = &group.gid;
    if ((rtn = snd_pcm_plugin_setup (pcm_handle, &setup)) < 0)
    {
        fprintf (stderr, "snd_pcm_plugin_setup failed: %s\n", snd_strerror (rtn));
        return -1;
    }
    printf ("Format %s \n", snd_pcm_get_format_name (setup.format.format));
    printf ("Frag Size %d \n", setup.buf.block.frag_size);
    printf ("Rate %d \n", setup.format.rate);
    bsize = setup.buf.block.frag_size;

    if (group.gid.name[0] == 0)
    {
        printf ("Mixer Pcm Group [%s] Not Set \n", group.gid.name);
        exit (-1);
    }
    printf ("Mixer Pcm Group [%s]\n", group.gid.name);
    if ((rtn = snd_mixer_open (&mixer_handle, card, setup.mixer_device)) < 0)
    {
        fprintf (stderr, "snd_mixer_open failed: %s\n", snd_strerror (rtn));
        return -1;
    }

    mSamples = FindTag (file1, "data");

    mSampleBfr1 = malloc (bsize);
    FD_ZERO (&rfds);
    FD_ZERO (&wfds);
    n = 1;
    while (N < mSamples && n > 0)
    {
        FD_SET (STDIN_FILENO, &rfds);
        FD_SET (snd_mixer_file_descriptor (mixer_handle), &rfds);
        FD_SET (snd_pcm_file_descriptor (pcm_handle, SND_PCM_CHANNEL_PLAYBACK), &wfds);

        rtn = max (snd_mixer_file_descriptor (mixer_handle),
            snd_pcm_file_descriptor (pcm_handle, SND_PCM_CHANNEL_PLAYBACK));

        if (select (rtn + 1, &rfds, &wfds, NULL, NULL) == -1)
            return err ("select");


        if (FD_ISSET (STDIN_FILENO, &rfds))
        {
            if ((rtn = snd_mixer_group_read (mixer_handle, &group)) < 0)
                fprintf (stderr, "snd_mixer_group_read failed: %s\n", snd_strerror (rtn));

            dev_raw (fileno (stdin));
            c = getc (stdin);
            dev_unraw (fileno (stdin));
            if (c != EOF)
            {
                switch (c)
                {
                case 'q':
                    group.volume.names.front_left += 10;
                    break;
                case 'a':
                    group.volume.names.front_left -= 10;
                    break;
                case 'w':
                    group.volume.names.front_left += 10;
                    group.volume.names.front_right += 10;
                    break;
                case 's':
                    group.volume.names.front_left -= 10;
                    group.volume.names.front_right -= 10;
                    break;
                case 'e':
                    group.volume.names.front_right += 10;
                    break;
                case 'd':
                    group.volume.names.front_right -= 10;
                    break;
                }
                if (group.volume.names.front_left > group.max)
                    group.volume.names.front_left = group.max;
                if (group.volume.names.front_left < group.min)
                    group.volume.names.front_left = group.min;
                if (group.volume.names.front_right > group.max)
                    group.volume.names.front_right = group.max;
                if (group.volume.names.front_right < group.min)
                    group.volume.names.front_right = group.min;
                if ((rtn = snd_mixer_group_write (mixer_handle, &group)) < 0)
                    fprintf (stderr, "snd_mixer_group_write failed: %s\n", snd_strerror (rtn));
            }
            else
                exit (0);

            printf ("Volume Now at %d:%d \n",
                100 * (group.volume.names.front_left - group.min) / (group.max - group.min),
                100 * (group.volume.names.front_right - group.min) / (group.max - group.min));

        }

        if (FD_ISSET (snd_mixer_file_descriptor (mixer_handle), &rfds))
        {
            snd_mixer_callbacks_t callbacks =
            {0, 0, 0, 0};

            snd_mixer_read (mixer_handle, &callbacks);
        }

        if (FD_ISSET (snd_pcm_file_descriptor (pcm_handle, SND_PCM_CHANNEL_PLAYBACK), &wfds))
        {
            snd_pcm_channel_status_t status;
            int     written = 0;

            if ((n = fread (mSampleBfr1, 1, min (mSamples - N, bsize), file1)) <= 0)
                continue;
            written = snd_pcm_plugin_write (pcm_handle, mSampleBfr1, n);
            if (written < n)
            {
                memset (&status, 0, sizeof (status));
                status.channel = SND_PCM_CHANNEL_PLAYBACK;
                if (snd_pcm_plugin_status (pcm_handle, &status) < 0)
                {
                    fprintf (stderr, "underrun: playback channel status error\n");
                    exit (1);
                }

                if (status.status == SND_PCM_STATUS_READY ||
                    status.status == SND_PCM_STATUS_UNDERRUN)
                {
                    if (snd_pcm_plugin_prepare (pcm_handle, SND_PCM_CHANNEL_PLAYBACK) < 0)
                    {
                        fprintf (stderr, "underrun: playback channel prepare error\n");
                        exit (1);
                    }
                }
                if (written < 0)
                    written = 0;
                written += snd_pcm_plugin_write (pcm_handle, mSampleBfr1 + written, n - written);
            }
            N += written;
        }
    }

    n = snd_pcm_plugin_flush (pcm_handle, SND_PCM_CHANNEL_PLAYBACK);

    rtn = snd_mixer_close (mixer_handle);
    rtn = snd_pcm_close (pcm_handle);
    fclose (file1);
    return (0);
}
网上找了个仿制 做的音频回波例子...
        编译应该不通过,不过我想说,如果楼主因为种种原因不方便给出源代码...

                    那各位亲为什么不动动手呢?   (不要比我还懒,这阵子好没心情呢...)

欢迎亲们访问   

额,百度比较难找的样子...

————————————————————
老公说这个代码和楼主的不怎么沾边,哈哈。随便搜索了下就贴上来了,大家不 要学我喔,我太懒了,不过想学的多查找多思考喔

[ 本帖最后由 pgy 于 2010-5-18 03:13 编辑 ]

我可好玩啦...不信你玩玩^_^
2010-05-17 23:59
StarWing83
Rank: 8Rank: 8
来 自:仙女座大星云
等 级:贵宾
威 望:19
帖 子:3951
专家分:748
注 册:2007-11-16
收藏
得分:0 
框架写出来了,剩下的就是公式的事儿了,我目前用的公式只能让x,y坐标其中之一相同的点震动= =Orz,明天来研究到底是什么公式= =

专心编程………
飞燕算法初级群:3996098
我的Blog
2010-05-18 00:54
StarWing83
Rank: 8Rank: 8
来 自:仙女座大星云
等 级:贵宾
威 望:19
帖 子:3951
专家分:748
注 册:2007-11-16
收藏
得分:0 
搞定了…………不过还有很多问题——比如,我这个一震动就停不下来了,我不知道怎么模拟真实震动时的能量消耗……

UPDATE:增加了阻尼……

- -|||


[ 本帖最后由 StarWing83 于 2010-5-18 04:09 编辑 ]
收到的鲜花
  • pgy2010-05-18 02:59 送鲜花  10朵   附言:老公~我爱死你啦~~~

专心编程………
飞燕算法初级群:3996098
我的Blog
2010-05-18 01:54
快速回复:###### 再发一个更好玩的东西 ######
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.069704 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved