公告:
精彩视频
348826281 元老 Fans 发消息
发表于 11-4-8 17:57:46 |显示全部楼层 来自: 中国河北廊坊
x蜗牛增压x 发表于 11-4-8 11:26
电车加速很快的 电路板会不会跟不上?

单片机能以每秒120~200次的速度更新转速,应该能跟上

用WRC的声音做的声音模拟器,主要是看重WRC的声音比较单调,好模仿,当然还有日本人做的那个“电车 发声装置
”。

效果没什么改进,经历这么多天又回到起点,很是郁闷。也许装车后,车辆跑起来产生多普勒效应,效果会好些。在http://www.rcfans.com/brand/上查了下2英寸的喇叭,功率4W,重量100克,还需要容积为200毫升的音箱,很占空间



声音的来源,Dirt3 的宣传片

x蜗牛增压x 论坛元老 发消息
发表于 11-4-8 18:05:45 |显示全部楼层 来自: 中国广东东莞
348826281 元老 Fans 发消息
发表于 11-5-15 12:00:56 |显示全部楼层 来自: 中国陕西西安
前段时间离校到单位报道,中断了一段时间

对声音的控制不再用电位器,换成舵机信号了。
如果变速播放发动机声音,油门快速变化时会出现像电子琴的声音,否定这个方法。


在外国人的文章里,他们用波形叠加的方法,把每个气缸的声音按一定间隔叠加。
synth.JPG
有文章介绍用GT-Suite软件的GT-power模块可以得到单缸声音的波形,可惜找不到那软件,只能现学FLUENT,建了个二维的直排管的模型,尾气排入一个半圆空间,计算压力
cfd.JPG

再用tecplot 360获得距离排气管口0.5m,偏移45度位置的压力波形。
ss.JPG
试着发出声音,一点都不像发动机,但油门快速变化时能正常发声,说明波形叠加的方法可行。

在上图中,压力的衰减相当快,如果安装消音器衰减更快,因此只要发动机转速不是很高,完全可以从实际的发动机连续工作的声音里截取波形。从ken block的漂移视频里截取了6个声音波形,
未命名.JPG
重写程序


听起来还是不爽。谁来指点下?????
也许找辆改装车,实地录制排气声音,会好点。宿舍外面的电子四路经常能听到改装车的声音,电子四路从电子西街至太白南路一段一直封闭,没车没人,六车道宽的柏油路是个很好的场地(西安)。

视频里用来产生舵机信号的板子,数码管中间一位不亮,电位器阻值跳动,弄的声音也跟着哆嗦,真是便宜没好货,工资一发就去去买个控。

348826281 元老 Fans 发消息
发表于 11-5-15 12:04:02 |显示全部楼层 来自: 中国陕西西安
本帖最后由 348826281 于 11-5-15 12:22 编辑

电路画的不标准,凑活看吧。声音信号可以直接输出到笔记本音箱,或者用LM386、TDA2422放大后输出到喇叭。还有个问题,小尺寸喇叭的频率下限,能否发出发动机的低频声音
circuit.JPG
熔丝配置,内部8M时钟,关闭看门狗计数器
fuse.JPG

代码 iccavr 写的不好,见笑了,对应2000~8000rpm的四缸机
原理:使用TC0和INT0测量舵机信号,用TC1按照声音采样率产生中断,叠加波形后由TC2的快速PWM发声。声音样本都是152长度,153~160的数值为中性点,当一段声音播放完就会指向这部分,不发出声音,直到再次开始播放

====声明:该代码无任何使用限制====

//ICC-AVR application builder : 2009-12-3 21:47:39
// Target : M8
// Crystal: 8.0000Mhz
#include
#include
unsigned int width,temp;
unsigned int n1,n2,n3,n4,n5,n6;//,n7,n8,n9,n10; // wave series position
char int_flag,bit8,wav_cfg;
char __flash (*p1);
char __flash (*p2);
char __flash (*p3);
char __flash (*p4);
char __flash (*p5);
char __flash (*p6);
// sample: 1~152   const"128": 153~160
__flash char acl1[160]={131,140,148,151,160,163,166,167,171,173,168,167,163,161,158,159,156,161,156,161,157,158,156,157,146,149,152,151,154,146,143,144,141,134,136,136,129,126,124,119,112,111,104,101,95,92,90,81,81,76,77,81,86,91,91,92,92,95,101,100,104,111,117,122,123,128,131,139,141,146,144,145,143,142,139,143,144,145,142,135,136,133,131,131,126,128,124,126,126,124,124,116,116,117,123,135,130,132,127,127,131,130,133,129,131,139,137,136,134,138,136,136,134,129,132,134,132,128,126,126,122,121,123,124,123,114,116,115,116,116,115,117,113,111,108,111,111,112,108,114,110,106,113,119,118,120,112,118,126,121,125,129,128,128,128,128,128,128,128,128};
__flash char acl2[160]={132,135,137,163,171,162,172,174,172,178,186,184,176,183,180,174,180,170,163,175,180,175,169,166,160,155,151,153,147,145,142,141,134,127,120,119,119,116,111,107,99,95,90,90,83,83,83,85,90,79,88,79,87,99,101,102,109,113,103,107,115,116,115,124,130,131,132,121,126,125,142,144,136,136,130,129,127,130,127,123,127,122,122,126,130,124,129,131,119,121,130,125,123,131,138,132,141,147,155,166,168,165,164,160,153,148,143,142,140,141,140,133,130,141,133,127,131,128,124,118,126,116,113,106,103,104,103,94,100,98,98,98,97,97,103,110,106,105,105,103,106,109,111,116,113,111,105,100,123,124,126,123,128,128,128,128,128,128,128,128};
__flash char acl3[160]={131,142,152,156,166,170,173,175,179,182,176,175,170,167,164,165,161,168,161,167,163,164,162,163,150,153,157,156,159,150,146,147,143,135,138,137,129,125,123,117,109,108,99,95,88,85,82,72,71,66,67,72,78,84,84,85,85,88,95,94,99,108,115,121,122,128,132,141,144,149,147,148,146,145,141,146,147,148,145,136,138,134,131,131,126,128,123,125,126,123,123,114,114,115,122,136,130,133,127,127,132,130,134,129,131,141,139,137,135,140,138,137,135,129,133,135,133,128,126,125,121,119,122,123,122,111,113,112,114,113,112,115,110,108,104,107,108,109,104,111,106,101,110,117,116,118,109,116,126,120,124,125,128,128,128,128,128,128,128,128};
__flash char acl4[160]={131,134,140,140,148,156,162,173,172,171,186,188,187,190,183,174,171,154,149,152,145,148,146,135,149,152,144,151,148,145,151,144,136,141,131,128,127,115,104,100,95,97,99,91,101,88,77,80,76,74,81,73,71,74,84,93,103,101,116,116,112,112,110,118,125,122,111,113,113,112,132,135,140,146,150,152,157,157,162,161,157,158,146,132,141,133,137,138,135,127,127,121,124,131,126,110,121,126,132,133,134,136,142,142,144,134,130,137,135,134,128,116,118,116,120,122,134,136,133,135,138,137,142,130,125,126,126,125,124,119,122,122,119,116,110,107,99,99,95,96,98,95,98,91,102,111,107,105,105,106,103,113,128,128,128,128,128,128,128,128};
__flash char acl5[160]={133,145,147,157,160,175,174,176,180,191,189,177,184,176,190,182,187,179,176,166,156,155,156,135,136,122,131,131,132,139,118,128,117,124,113,123,130,113,114,90,98,90,91,86,84,86,89,84,83,89,105,93,97,96,103,101,105,110,114,119,120,121,138,136,144,137,143,138,137,126,129,128,131,127,129,129,136,136,136,136,138,134,128,136,133,131,126,128,124,125,132,132,140,140,159,145,145,139,135,145,136,124,127,124,133,119,149,140,148,141,118,135,125,138,128,124,123,121,114,103,112,114,126,119,118,117,123,109,98,121,111,121,101,112,96,95,94,89,100,92,117,99,109,105,100,115,112,132,119,121,124,122,128,128,128,128,128,128,128,128};
__flash char acl6[160]={130,135,137,147,156,166,174,176,180,179,181,176,179,179,175,170,165,158,153,158,161,155,153,146,145,142,142,141,146,144,145,142,130,129,123,120,119,119,118,114,109,102,98,95,93,91,90,90,95,89,86,90,92,99,103,102,102,94,101,105,113,120,125,124,123,118,117,122,130,137,143,150,149,151,157,158,160,158,155,151,149,143,138,140,137,131,128,129,126,128,121,119,118,118,126,128,132,135,134,127,129,129,128,130,131,135,136,136,141,143,145,139,137,134,130,127,125,120,120,122,126,130,123,123,122,122,126,117,116,111,110,107,107,104,100,95,96,101,111,112,110,108,108,106,108,108,112,117,120,121,123,126,128,128,128,128,128,128,128,128};
__flash char interval[128]={150,146,143,140,137,134,131,128,126,123,121,119,116,114,112,110,108,107,105,103,101,100,98,97,95,94,92,91,
90,88,87,86,85,84,83,82,80,79,78,77,77,76,75,74,73,72,71,70,70,69,68,67,67,66,65,65,64,63,63,62,61,61,60,60,59,59,58,58,57,56,56,55,55,
55,54,54,53,53,52,52,51,51,51,50,50,49,49,49,48,48,47,47,47,46,46,46,45,45,45,44,44,44,44,43,43,43,42,42,42,41,41,41,41,40,40,40,40,39,
39,39,39,38,38,38,38,38,37,37};
void port_init(void)
{
PORTB = 0x00;
DDRB  = 0x08; //PB3 --> OC2  output
PORTC = 0x00; //m103 output only
DDRC  = 0x00; //
PORTD = 0x00;
DDRD  = 0x00; //PD2 -->INT0 input
}
//TIMER0 initialize - prescale:8
void timer0_init(void)
{
TCCR0 = 0x00; //stop
TCNT0 = 0x00; //set count
TCCR0 = 0x02; //start timer
}
#pragma interrupt_handler timer0_ovf_isr:iv_TIM0_OVF
void timer0_ovf_isr(void)
{
bit8++; // expand TC0 range
}
#pragma interrupt_handler int0_isr:iv_INT0
void int0_isr(void)
{ //external interupt on INT0
if (int_flag==1)  // INT0 rising edge
   {
    timer0_init(); //start TC0
    MCUCR = 0x02;  // INT0 falling edge
int_flag=0;
   }
else {TCCR0 = 0x00; //stop TC0
     //width=unsigned int(TCNT0)+256*unsigned int(bit8)-1500; // 0~500, 1.5ms~2ms
  //width=(TCNT0>>2)+64*bit8-375; //0~500 divide by 4, 0~125
  width=(TCNT0>>2)+64*bit8;
  if (width>375)   //make sure width >=0
  {width=width-375;}
  else width=0;
  
  MCUCR = 0x03;  // INT0 rising edge
  int_flag=1;
  bit8=0;
  
  if(width>125)  // make sure width <=125
  {width=125;}
  
   }
}

//TIMER1 initialize - prescale:8
// WGM: 4) CTC, TOP=OCRnA
// desired value: 10000Hz
// actual value: 10000.000Hz (0.0%)
void timer1_init(void)
{
TCCR1B = 0x00; //stop
TCNT1H = 0xFF; //setup
TCNT1L = 0x9D;
OCR1AH = 0x00;
OCR1AL = 0x63;
OCR1BH = 0x00;
OCR1BL = 0x63;
ICR1H  = 0x00;
ICR1L  = 0x63;
TCCR1A = 0x00;
TCCR1B = 0x0A; //start Timer
}
#pragma interrupt_handler timer1_compa_isr:iv_TIM1_COMPA
void timer1_compa_isr(void)
{ //compare occured TCNT1=OCR1A
// add a new wavform into serias, push former waveform ...
   if (n1>interval[width])
   {//n10=n9;n9=n8;n8=n7;n7=n6;
   n6=n5;n5=n4;n4=n3;n3=n2;n2=n1;n1=0;
   }
   
   switch(wav_cfg)
   {case 1:p1=acl1;p2=acl2;p3=acl3;p4=acl4;p5=acl5;p6=acl6;wav_cfg++;break;
    case 2:p1=acl6;p2=acl1;p3=acl2;p4=acl3;p5=acl4;p6=acl5;wav_cfg++;break;
    case 3:p1=acl5;p2=acl6;p3=acl1;p4=acl2;p5=acl3;p6=acl4;wav_cfg++;break;
    case 4:p1=acl4;p2=acl5;p3=acl6;p4=acl1;p5=acl2;p6=acl3;wav_cfg++;break;
    case 5:p1=acl3;p2=acl4;p3=acl5;p4=acl6;p5=acl1;p6=acl2;wav_cfg++;break;
    case 6:p1=acl2;p2=acl3;p3=acl4;p4=acl5;p5=acl6;p6=acl1;wav_cfg=1;break;
   default:p1=acl1;p2=acl2;p3=acl3;p4=acl4;p5=acl5;p6=acl6;
   }
// waveform neutral point is 128, need some modify
   temp=*(p1+n1)+*(p2+n2)+*(p3+n3)+*(p4+n4)+*(p5+n5)+*(p6+n6)-640; //640=128*5
   OCR2 = (char)temp;
   
     if (n1>=151)
    { n1=0; }
  else n1++;
  
  if (n2>=151)
    { n2=155; }
  else n2++;
  
  if (n3>=151)
    { n3=155; }
  else n3++;
  
  if (n4>=151)
    { n4=155; }
  else n4++;
  
  if (n5>=151)
    { n5=155; }
  else n5++;
  
  if (n6>=151)
    { n6=155; }
  else n6++;
      
}

//TIMER2 initialize - prescale:1
// WGM: PWM Fast
// actual value: 31250.000Hz (100.0%)
void timer2_init(void)
{
TCCR2 = 0x00; //stop
ASSR  = 0x00; //set async mode
TCNT2 = 0x01; //setup
OCR2  = 0x8F;
TCCR2 = 0x69; //start 0110 1001
}

//call this routine to initialize all peripherals
void init_devices(void)
{
//stop errant interrupts until set up
CLI(); //disable all interrupts
port_init();
//timer0_init();
timer2_init();
timer1_init();

MCUCR = 0x03;  // INT0 rising edge
GICR  = 0x40; // INT0 enable
TIMSK = 0x11; //timer interrupt sources 0001 0001
SEI(); //re-enable interrupts
//all peripherals are now initialized
}
void main(void)
{wav_cfg=1;p1=acl1;p2=acl2;p3=acl3;p4=acl4;p5=acl5;p6=acl6;
    n1=0;n2=155;n3=155;n4=155;n5=155;n6=155;
int_flag=1;bit8=0;width=0;
init_devices();

while (1)
{
} //while(1)
} //main

hex文件可以从http://bbs.5imx.com/bbs/viewthread.php?tid=475228&page=1&extra=page%3D7下载
头像被屏蔽
发表于 11-5-16 00:21:13 |显示全部楼层 来自: 中国福建福州
提示: 作者被禁止或删除 内容自动屏蔽
even107 金牌 Fans 发消息
发表于 11-5-16 02:55:08 |显示全部楼层 来自: 意大利
其实早就有这个东东卖了。

点评

無雙  你好朋友,请问一下模似发动机的声效器那里有卖的啊?想给电车装一个这个东西  发表于 11-9-14 20:16
晓帕 高级 Fans 发消息
发表于 11-5-17 09:16:21 |显示全部楼层 来自: 中国天津

null

支持楼主,期待更新产品;-))
348826281 元老 Fans 发消息
发表于 11-5-19 19:25:28 |显示全部楼层 来自: 中国陕西西安
even107 发表于 11-5-16 02:55
其实早就有这个东东卖了。

已经有人做过了吗?贴个链接吧,要是效果好,我就直接买一个。自己做太费劲
348826281 元老 Fans 发消息
发表于 11-5-19 19:34:09 |显示全部楼层 来自: 中国陕西西安
关于波形叠加的正确性

在网上找到这个视频


截取声音后观察波形,看到两个大的波之间夹杂小的波
sti lo.JPG

放大看,大的波是排气的压力波,小的波是气体在排气管里振荡产生的
sti lo 1.JPG

在高转速区,排气压力波的间距缩短,和之前小的波叠加,有时会产生毛刺。
sti hi.JPG

所以波形叠加模拟排气声是可行的

348826281 元老 Fans 发消息
发表于 11-5-19 20:01:43 |显示全部楼层 来自: 中国陕西西安
本帖最后由 348826281 于 11-5-19 20:07 编辑

略有进展

之前的变速率播放方案因为所谓的“电子琴声”而放弃,但那讨厌的声音同样出现在波形叠加方案中,分析后得出结论:“电子琴声”实际是声音的阶梯式跳变,不连续,所以出现那种声音。查出问题在那个自制的舵机测试机,更新的速度慢,导致声音模拟器出现怪声。修复后,变速率播放就能发出比较好的声音,在快速变化时也有较好表现。(舵机信号的50Hz频率足够了,不会导致电子琴声)

WRC版本,前进时发声,并根据油门大小变化,倒车时声音减弱且恒定(目前不能分辨是倒车还是刹车,所以倒车无声)


坦克声音版本,双向发声,攀爬用估计合适



源代码和烧录单片机用的Hex文件
http://bbs.5imx.com/bbs/viewthread.php?tid=475228&pid=6237383&page=1&extra=

您需要登录后才可以回帖 登录 | 注册

广告投放|联系我们|手机|投稿|Archiver|About us|Advertise|遥控迷模型网|RCFans ( 粤ICP备10210518号-1 )

版权所有 RCFans.com © 2003-2016

返回顶部