0
  • 聊天消息
  • 系统消息
  • 评论与回复
登录后你可以
  • 下载海量资料
  • 学习在线课程
  • 观看技术视频
  • 写文章/发帖/加入社区
会员中心
创作中心

完善资料让更多小伙伴认识你,还能领取20积分哦,立即完善>

3天内不再提示

如何使用Arduino Processing和Wekinator按钮更改声音播放器的音高

454398 来源:工程师吴畏 2019-07-30 14:33 次阅读
加入交流群
微信小助手二维码

扫码添加小助手

加入工程师交流群

设置Arduino Board

这个项目使用连接到Arduino Uno的五个按钮。使用Arduino为按钮建立连接,如下图所示。

项目草图

在输入端,我们将有一个Arduino草图和一个Processing草图。 Arduino草图将读取五个按钮的状态,并通过串行通信将其转发到Processing。 Processing sketch将接收此数据,并通过OSC(开放式声音控制)协议将其转发给Wekinator。

Arduino Sketch

#define buttonPin1 6

#define buttonPin2 5

#define buttonPin3 4

#define buttonPin4 3

#define buttonPin5 2

int inByte = 0; // incoming serial byte

// the setup function runs once when you press reset or power the board

void setup() {

Serial.begin(115200);

pinMode(buttonPin1, INPUT);

pinMode(buttonPin2, INPUT);

pinMode(buttonPin3, INPUT);

pinMode(buttonPin4, INPUT);

pinMode(buttonPin5, INPUT);

establishContact(); // send a byte to establish contact until receiver

// responds

}

// the loop function runs over and over again forever

void loop() {

// if we get a valid byte, read button pins:

if (Serial.available() 》 0) {

// get incoming byte:

inByte = Serial.read();

// read the state of the pushbuttons:

int buttonState1 = digitalRead(buttonPin1);

int buttonState2 = digitalRead(buttonPin2);

int buttonState3 = digitalRead(buttonPin3);

int buttonState4 = digitalRead(buttonPin4);

int buttonState5 = digitalRead(buttonPin5);

Serial.write(buttonState1);

Serial.write(buttonState2);

Serial.write(buttonState3);

Serial.write(buttonState4);

Serial.write(buttonState5);

}

}

void establishContact() {

while (Serial.available() 《= 0) {

Serial.print(‘A’); // send a capital A

delay(300);

}

}

处理草图

import processing.serial.*;

import oscP5.*;

import netP5.*;

OscP5 oscP5;

NetAddress dest;

Serial myPort; // The serial port

int[] serialInArray = new int[5]; // Where we‘ll put what we receive

int serialCount = 0; // A count of how many bytes we receive

int button1, button2, button3, button4, button5;

boolean firstContact = false; // Whether we’ve heard from the microcontroller

void setup() {

size(256, 256); // Stage size

noStroke(); // No border on the next thing drawn

// Print a list of the serial ports, for debugging purposes:

println(Serial.list());

// I know that the first port in the serial list on my mac

// is always my FTDI adaptor, so I open Serial.list()[0]。

// On Windows machines, this generally opens COM1.

// Open whatever port is the one you‘re using.

String portName = Serial.list()[0];

myPort = new Serial(this, portName, 115200);

/* start oscP5, sending messages at port 9000 */

oscP5 = new OscP5(this,9000);

dest = new NetAddress(“127.0.0.1”,6448);

}

void draw() {

//Send the OSC message

sendOsc();

}

void serialEvent(Serial myPort) {

// read a byte from the serial port:

int inByte = myPort.read();

// if this is the first byte received, and it’s an A,

// clear the serial buffer and note that you‘ve

// had first contact from the microcontroller.

// Otherwise, add the incoming byte to the array:

if (firstContact == false) {

if (inByte == ’A‘) {

myPort.clear(); // clear the serial port buffer

firstContact = true; // you’ve had first contact from the microcontroller

myPort.write(‘A’); // ask for more

}

}

else {

// Add the latest byte from the serial port to array:

serialInArray[serialCount] = inByte;

serialCount++;

// If we have 3 bytes:

if (serialCount 》 4 ) {

button1 = serialInArray[0];

button2 = serialInArray[1];

button3 = serialInArray[2];

button4 = serialInArray[3];

button5 = serialInArray[4];

// print the values (for debugging purposes only):

println(button1 + “&” + button2 + “&” + button3 + “&” + button4 + “&” + button5);

// Send a capital A to request new sensor readings:

myPort.write(‘A’);

// Reset serialCount:

serialCount = 0;

}

}

}

void sendOsc() {

OscMessage msg = new OscMessage(“/wek/inputs”);

msg.add((float)button1);

msg.add((float)button2);

msg.add((float)button3);

msg.add((float)button4);

msg.add((float)button5);

oscP5.send(msg, dest);

}

设置ChucK

在输出端,我们可以使用ChucK从Wekinator接收五个连续输出,并根据这些输出发出声音。

下载您正在使用的操作系统的FM Synthesis示例。

现在打开终端并转到您放置它的目录并输入以下行:

chuck FMSynth_5ContinousOutputs.ck

Chuck将开始收听Wekinator的输出并接收输出,它将改变声音的音高。

设置Wekinator

现在打开Wekinator并对设置进行以下调整:

将输入设置为5并输出为5

选择输出键入到所有连续

Wekinator将从Processing接收五个输入,并在训练后将向Chuck发送五个不同的输出。从那里,ChucK将根据Wekinator输出产生不同的声音。

点击 下一步 按钮,您将看到此窗口:

按第一个按钮,然后单击 随机化 。开始录制一秒钟,它将记录一些样本。

按第二个按钮,然后单击 随机化 的。然后记录一秒。

同样,记录其他三个按钮的样本。

记录五个样本后,单击在 火车 上训练Wekinator。然后单击 运行 。现在当您按下按钮时,程序将根据您提供的输入发出声音。

相关项目

如何构建Arduino演讲者几分钟播放音乐

声明:本文内容及配图由入驻作者撰写或者入驻合作网站授权转载。文章观点仅代表作者本人,不代表电子发烧友网立场。文章及其配图仅供工程师学习之用,如有内容侵权或者其他违规问题,请联系本站处理。 举报投诉
  • Processing
    +关注

    关注

    0

    文章

    11

    浏览量

    9252
  • Arduino
    +关注

    关注

    190

    文章

    6527

    浏览量

    197452
收藏 人收藏
加入交流群
微信小助手二维码

扫码添加小助手

加入工程师交流群

    评论

    相关推荐
    热点推荐

    语音芯片怎么样写入声音?一文讲透语音播放芯片的声音写入之道

    如果说芯片是电子产品的“大脑”,那么语音芯片就是赋予设备“声音灵魂”的关键元器件。从商场迎宾、电动车报警,到智能门锁、医疗设备,凡是需要“开口说话”的设备,内部都藏着一颗或多颗能将数字信号转化
    的头像 发表于 04-24 10:04 30次阅读
    语音芯片怎么样写入<b class='flag-5'>声音</b>?一文讲透语音<b class='flag-5'>播放</b>芯片的<b class='flag-5'>声音</b>写入之道

    语音芯片也能同时播放10种声音?广州唯创电子WTR096A-16S混音芯片带来音频体验新突破

    引言:当单一声音已不足以表达创意在智能硬件快速迭代的今天,音频播放早已不满足于“能响就行”。从沉浸式游戏音效到多声源背景广播,从教育产品的交互提示到智能家居的场景反馈——单一语音通道越来越难以承载
    的头像 发表于 04-10 08:55 346次阅读
    语音芯片也能同时<b class='flag-5'>播放</b>10种<b class='flag-5'>声音</b>?广州唯创电子WTR096A-16S混音芯片带来音频体验新突破

    TLV320AIC28立体声音频编解码:高性能音频解决方案解析

    TLV320AIC28立体声音频编解码:高性能音频解决方案解析 在当今的电子设备中,音频体验是至关重要的一环。无论是智能手机、MP3 播放器还是数码摄像机,都需要高质量的音频编解码
    的头像 发表于 02-03 14:50 492次阅读

    TLV320AIC3262:低功耗立体声音频编解码的卓越之选

    频编解码,凭借其丰富的功能和出色的性能,在移动设备、便携式媒体播放器等领域得到了广泛应用。今天,我们就来深入了解一下这款产品。 文件下载: tlv320aic3262.pdf 1. 功能特性:集多种
    的头像 发表于 01-30 14:40 376次阅读

    花椒直播开源鸿蒙专属直播播放器 助力高效开发高性能直播应用

    近日,花椒直播开源了专注于直播场景的播放器“HJPlayer”。它基于自研的通用多媒体框架“HJMedia”打造,与早前开源的推流“HJPusher”共同构成了覆盖主播推流到观众播放的完整客户端
    的头像 发表于 10-22 11:20 501次阅读
    花椒直播开源鸿蒙专属直播<b class='flag-5'>播放器</b> 助力高效开发高性能直播应用

    N9H26播放视频为什么没有声音

    为什么播放视频 (MJPEG MP3) 但没有声音
    发表于 09-01 08:17

    如何使用 M487 微控制 (MCU) 通过 DAC 在 SD 卡上播放 WAV 文件声音

    使用 M487 微控制 (MCU) 通过 DAC 在 SD 卡上播放 WAV 文件声音
    发表于 08-20 06:05

    创通联达助力飞傲M27革新便携HiFi播放器体验

    2025年8月15日,飞傲在第19届深圳国际音频展(SIAS)正式发布年度旗舰播放器FIIO M27。作为基于创通联达TurboX C6490 SOM打造的标杆产品,M27凭借该模块的卓越性能与飞傲自研声学技术形成协同突破,为用户带来全方位、全场景的优秀音频体验,全面革新便携HiFi
    的头像 发表于 08-19 16:15 2418次阅读

    多路混音声音播放芯片型号推荐

    以下是唯创知音旗下主流的多路声音播放芯片深度解析,结合精准参数、丰富场景及技术特性,满足智能设备多样化音频需求: 一、WTV380/890 系列:高集成多模态交互芯片 核心参数 通道能力:支持8 路
    的头像 发表于 08-15 16:51 1023次阅读

    【创龙TL3562-MiniEVM开发板试用体验】9、带音频波形显示的QT音乐播放器

    时域波形:直观展示声音的音量变化 (如声波的震动幅度),默认情况下显示的是时域信号。,而不是频率。数据来源是原始PCM样本。 在 Qt 中为音频播放器增加频谱显示功能,可以通过
    发表于 08-08 19:18

    蜻蜓FM开源“SmartXPlayer”音频播放组件,打造鸿蒙多端音频播放新引擎

    分布式能力和多线程架构,提供高性能、易集成的音频播放能力支持,助力开发者高效构建更顺滑、更智能、更便捷的音频播放体验。 当前,随着音频内容和智能设备的普及,传统播放器在多端适配、分布式投播、主线程阻塞等方面存在开发难、效率低、体
    的头像 发表于 07-21 16:31 749次阅读
    蜻蜓FM开源“SmartXPlayer”音频<b class='flag-5'>播放</b>组件,打造鸿蒙多端音频<b class='flag-5'>播放</b>新引擎

    Made with KiCad(135):Echo - 开源的音乐播放器

    “  Echo 是一个开源硬件平台,专为音乐播放器设计。该项目的目标是开发一款基于开源软件并采用开源设计的高品质音乐播放器。 ”   Made with KiCad 系列将支持新的展示方式。直接将以
    的头像 发表于 07-16 11:17 3360次阅读
    Made with KiCad(135):Echo - 开源的音乐<b class='flag-5'>播放器</b>

    在使用EZ-USB® FX3™ 设备时,上电后相机开始正常工作,但延时10s左右播放器才能够显示图像数据?为什么?

    在使用EZ-USB® FX3™ 设备时,上电后相机开始正常工作,但延时10s左右播放器才能够显示图像数据?这是由于固件中的某些设置问题吗?
    发表于 07-16 07:08

    基于STM32的音乐播放器电路+PCB源文件+源码+论文等打包下载

    基于STM32的音乐播放器电路+PCB源文件+源码+论文等打包,推荐下载!
    发表于 05-29 21:37

    BT.1120摄像头与DEMO_FX3_LVDS_CAM01接口套件连接,在eBUS播放器显示屏上未显示任何内容是怎么回事?

    BT.1120 摄像头与 DEMO_FX3_LVDS_CAM01 接口套件连接,但在 eBUS 播放器显示屏上未显示任何内容。
    发表于 04-30 08:03