- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在创建一个鼓应用程序,我必须在其中做两件事
最佳答案
两部分答案:
解决方案一 :想到的一个想法是,与其尝试录制生成的音频,不如录制他们按下的按钮,并在他们播放文件时重新创建序列。
所以你的“录音”文件会是这样的:
/* Create a .WAV file with a specified set of chirps */
#include<stdio.h>
#include<sys\stat.h>
#include<ctype.h>
/* length of one bit in 44100Hz units */
#define BIT_LEN 88.5
/* length of one half-cycle */
#define HALF_CYCLE (BIT_LEN/8)
/* samples per second */
#define SAMP_RATE 44100
/* seconds before chirps start */
#define LEAD_SILENCE 5
struct {
unsigned long ID; /* FILE ID "RIFF" */
unsigned long Len; /* file length (excluding 8-byte header) */
unsigned long DataType; /* Data type 'WAVE' (start of main file) */
} FileHeader;
struct {
unsigned long ID; /* chunk ID "DATA" */
unsigned long Len; /* chunk length */
} DataHeader;
struct {
unsigned long ID; /* chunk ID "FMT " */
unsigned long Len; /* chunk length */
short FormatTag; /* format (1 if uncompressed) */
unsigned short Channels; /* # of channels (mono, stereo, etc) */
unsigned long SampPerSec; /* # of samples per second */
unsigned long AvgBytesPerSec; /* # of bytes played per second */
unsigned short BlockAlign; /* Size of a 'frame' in bytes */
unsigned short BitsPerSamp; /* bits per sample */
} FormatHeader;
#define ID_RIFF 0x46464952 /* 'RIFF' (FFIR) */
#define ID_WAVE 0x45564157 /* 'WAVE' (EVAW) */
#define ID_DATA 0x61746164 /* 'data' (atad) */
#define ID_FMT 0x20746d66 /* 'fmt ' ( tmf)*/
/* count # of pos/negative parts done */
int pcount=0;
/* how many will fit on a normal line? */
#define PCOUNT_MAX 14
void disp_id( char * lbl, long ID )
{
union {
long l;
char c[6];
} u;
u.l = ID;
u.c[4] = 0;
printf( lbl, u.c );
}
/* note where the samples begin */
unsigned long SampleStart; /* where do samples begin? */
/* one-second chirp segment */
short NewChirp[SAMP_RATE], /* 1-second block with chirp */
Silence[SAMP_RATE]; /* 1-second silence */
/* insert a byte into the chirp */
/* location is specified in bit time units */
void insert_byte( int location, int value )
{
int i, j;
int data; /* value to write to item */
int dloc; /* where we are within the byte */
int cycle;
printf("Inserting byte %d", value);
/* insert bits in little-endian order */
data = (value<<2) + 2; /* add "10" to the number */
/* round cycle low/high times to 11 samples low, 11 samples high */
/* use BIT_LEN to put it in the proper place */
for( i=0; i<10; i++ )
if ( data & (1<<i) )
{
printf(" %d: ", i );
/* have a 1-bit to insert, where should it be? */
/* insert 4 cycles */
for( cycle=0; cycle<4; cycle++ )
{
/* note: this may leave 0 samples between cycles or bits */
dloc = (int)(location + i*BIT_LEN + cycle*(BIT_LEN/4) + 0.5);
printf(" %d", dloc );
/* insert 11 low samples */
for( j=0; j<11; j++ )
{
NewChirp[ dloc+j ] = -30000;
}
/* insert 11 high samples */
for( j=11; j<22; j++ )
{
NewChirp[ dloc+j ] = 30000;
}
}
}
printf("\n");
} /* insert_byte */
/* insert a chirp with the given value */
void insert_chirp( FILE *f, float speed, float incline )
{
int i, i_speed, i_incline, i_chksum;
/* convert values to integers */
i_speed = (int)( speed*10 + 0.5 );
i_incline = (int)( incline*10 + 0.5 );
i_chksum = (i_speed + i_incline) & 0x0ff;
/* set everything to 0 in advance */
memset( NewChirp, 0, SAMP_RATE );
/* start inserting chirp parts */
insert_byte( 0, i_speed );
insert_byte( (int)(10*BIT_LEN+0.5), i_incline );
insert_byte( (int)(20*BIT_LEN+0.5), i_chksum );
insert_byte( (int)(40*BIT_LEN+0.5), i_speed );
insert_byte( (int)(50*BIT_LEN+0.5), i_incline );
insert_byte( (int)(60*BIT_LEN+0.5), i_chksum );
/* write the chirp */
fwrite( NewChirp, 1, SAMP_RATE, f );
} /* insert_chirp */
/* maximum # of chirps per file we will permit */
#define CHIRP_MAX 50
int main(int argc, char *argv[])
{
FILE *f; /* workout information file */
FILE *audio; /* output WAV file */
/* hold information about the chirps */
struct {
int second_count; /* where does this occur in seconds */
float speed; /* speed to use */
float incline; /* treadmill incline */
} chirp_list[CHIRP_MAX+1];
int chirp_count; /* # of chirps in the current workout */
int cur_chirp; /* which chirp are we working on? */
int cur_time; /* current time we are writing */
char wname[100]; /* workout name from the file */
int len;
char dbuf[100]; /* one chirp line from the file */
/* for reading one chirp */
int sec;
int seqno;
float speed, incline;
int sec_length; /* length of workout in seconds */
printf("initializaing\n");
/* build our 1 second of silence */
memset( Silence, 0, SAMP_RATE );
printf("opening input file %s\n", argv[1] );
/* open the description file */
fopen_s( &f, argv[1], "r" );
if ( f == NULL )
{
printf("Unable to open file %s\n", argv[1] );
return 1;
}
/* read one workout from the file */
while( 1==1 )
{
printf("reading one line from the workout\n");
/* at end of file? */
if ( feof(f) )
{
return 0;
}
/* get the header line */
fgets( wname, 90, f );
/* did we now detect end of file? */
if ( feof(f) )
{
return 0;
}
/* read the workout stages */
chirp_count = 0;
sec_length = 45; /* account for lead and trail time */
while( 1==1) {
fgets( dbuf, 90, f );
printf("read line %s", dbuf );
/* did we now detect end of file? - Shouldn't happen, but check */
if ( feof(f) || strlen(dbuf)<3 )
{
break;
}
if ( ! isdigit( dbuf[0] ) )
{
/* should have only numbers here */
return 3;
}
/* extract the information */
sscanf_s( dbuf, "%d %f %f %d", &seqno, &speed, &incline, &sec );
printf("speed=%3.1f, incline=%3.1f, time=%d\n", speed, incline, sec );
/* save it for later */
chirp_list[chirp_count].second_count = sec;
sec_length += sec;
chirp_list[chirp_count].speed = speed;
chirp_list[chirp_count].incline = incline;
/* move to next chirp */
chirp_count++;
}
/* replace ".txt" with ".wav" for the output filename */
if ( strlen( argv[1] ) > 90 )
{
printf("Error: path/filename too long\n");
exit(1);
}
strcpy( wname, argv[1] );
strcpy( wname+strlen(wname)-3, "wav" );
/* start creating our WAV file */
printf("Creating output file %s\n", wname );
fopen_s( &audio, wname, "wb" );
printf("Overall length: %d seconds\n", sec_length );
/* create header */
FileHeader.ID = ID_RIFF;
FileHeader.DataType = ID_WAVE;
/* create our format header */
FormatHeader.ID = ID_FMT;
FormatHeader.Len = 16; /* chunk length */
FormatHeader.FormatTag = 1; /* format (1 if uncompressed) */
FormatHeader.Channels = 1; /* # of channels */
FormatHeader.SampPerSec = SAMP_RATE; /* # of samples per second */
FormatHeader.AvgBytesPerSec = SAMP_RATE*2; /* # of bytes played per second */
FormatHeader.BlockAlign = 1; /* Size of a 'frame' in bytes */
FormatHeader.BitsPerSamp = 16; /* bits per sample */
/* create our data header */
DataHeader.ID = ID_DATA;
DataHeader.Len = (sec_length+LEAD_SILENCE) * SAMP_RATE;
/* update overall length, account for various headers except main RIFF part */
/* -- include 'WAVE' part of main header */
FileHeader.Len = DataHeader.Len + 4 +
+ sizeof(FormatHeader) + sizeof( DataHeader );
/* write it to the file */
fwrite( &FileHeader, sizeof(FileHeader), 1, audio );
/* write it to the file */
fwrite( &FormatHeader, sizeof(FormatHeader), 1, audio );
/* write it to the file */
fwrite( &DataHeader, sizeof(DataHeader), 1, audio );
/* start with silence */
printf("Writing lead-in\n" );
for( cur_time = 0; cur_time < LEAD_SILENCE; cur_time++ )
{
fwrite( &Silence, 1, SAMP_RATE, audio );
}
/* now do the chirps */
for( cur_chirp=0; cur_chirp < chirp_count; cur_chirp++ )
{
printf("Chirp #%d, time=%d, speed=%4.1f, incline=%4.1f\n",
cur_chirp+1, chirp_list[cur_chirp].second_count,
chirp_list[cur_chirp].speed, chirp_list[cur_chirp].incline );
/* add the chirp */
insert_chirp( audio, chirp_list[cur_chirp].speed,
chirp_list[cur_chirp].incline );
/* add enough silence between this chirp and the next */
for( cur_time = 1;
cur_time < chirp_list[cur_chirp].second_count; cur_time++ )
{
/* add another second of silence */
fwrite( &Silence, 1, SAMP_RATE, audio );
}
}
/* add the stop chirp */
printf("Stop chirp\n");
insert_chirp( audio, 25.2, 25.2 );
/* end with 30 seconds of silence */
printf("Writing 30 seconds lead-out\n" );
for( cur_time = 1; cur_time < 30; cur_time++ )
{
fwrite( &Silence, 1, SAMP_RATE, audio );
}
/* done with this workout */
fclose( audio );
} /* while reading workouts */
}
关于android - 如何从 Android 中的多个声音 block 创建单个声音文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31920890/
我最近在/ drawable中添加了一些.gifs,以便可以将它们与按钮一起使用。这个工作正常(没有错误)。现在,当我重建/运行我的应用程序时,出现以下错误: Error: Gradle: Execu
Android 中有返回内部存储数据路径的方法吗? 我有 2 部 Android 智能手机(Samsung s2 和 s7 edge),我在其中安装了一个应用程序。我想使用位于这条路径中的 sqlit
这个问题在这里已经有了答案: What's the difference between "?android:" and "@android:" in an android layout xml f
我只想知道 android 开发手机、android 普通手机和 android root 手机之间的实际区别。 我们不能从实体店或除 android marketplace 以外的其他地方购买开发手
自Gradle更新以来,我正在努力使这个项目达到标准。这是一个团队项目,它使用的是android-apt插件。我已经进行了必要的语法更改(编译->实现和apt->注释处理器),但是编译器仍在告诉我存在
我是android和kotlin的新手,所以请原谅要解决的一个非常简单的问题! 我已经使用导航体系结构组件创建了一个基本应用程序,使用了底部的导航栏和三个导航选项。每个导航选项都指向一个专用片段,该片
我目前正在使用 Facebook official SDK for Android . 我现在正在使用高级示例应用程序,但我不知道如何让它获取应用程序墙/流/状态而不是登录的用户。 这可能吗?在那种情
我在下载文件时遇到问题, 我可以在模拟器中下载文件,但无法在手机上使用。我已经定义了上网和写入 SD 卡的权限。 我在服务器上有一个 doc 文件,如果用户单击下载。它下载文件。这在模拟器中工作正常但
这个问题在这里已经有了答案: What is the difference between gravity and layout_gravity in Android? (22 个答案) 关闭 9
任何人都可以告诉我什么是 android 缓存和应用程序缓存,因为当我们谈论缓存清理应用程序时,它的作用是,缓存清理概念是清理应用程序缓存还是像内存管理一样主存储、RAM、缓存是不同的并且据我所知,缓
假设应用程序 Foo 和 Eggs 在同一台 Android 设备上。任一应用程序都可以获取设备上所有应用程序的列表。一个应用程序是否有可能知道另一个应用程序是否已经运行以及运行了多长时间? 最佳答案
我有点困惑,我只看到了从 android 到 pc 或者从 android 到 pc 的例子。我需要制作一个从两部手机 (android) 连接的 android 应用程序进行视频聊天。我在想,我知道
用于使用 Android 以编程方式锁定屏幕。我从 Stackoverflow 之前关于此的问题中得到了一些好主意,并且我做得很好,但是当我运行该代码时,没有异常和错误。而且,屏幕没有锁定。请在这段代
文档说: android:layout_alignParentStart If true, makes the start edge of this view match the start edge
我不知道这两个属性和高度之间的区别。 以一个TextView为例,如果我将它的layout_width设置为wrap_content,并将它的width设置为50 dip,会发生什么情况? 最佳答案
这两个属性有什么关系?如果我有 android:noHistory="true",那么有 android:finishOnTaskLaunch="true" 有什么意义吗? 最佳答案 假设您的应用中有
我是新手,正在尝试理解以下 XML 代码: 查看 developer.android.com 上的文档,它说“starStyle”是 R.attr 中的常量, public static final
在下面的代码中,为什么当我设置时单选按钮的外观会发生变化 android:layout_width="fill_parent" 和 android:width="fill_parent" 我说的是
很难说出这里要问什么。这个问题模棱两可、含糊不清、不完整、过于宽泛或夸夸其谈,无法以目前的形式得到合理的回答。如需帮助澄清此问题以便重新打开,visit the help center . 关闭 9
假设我有一个函数 fun myFunction(name:String, email:String){},当我调用这个函数时 myFunction('Ali', 'ali@test.com ') 如何
我是一名优秀的程序员,十分优秀!