0
  • 聊天消息
  • 系統(tǒng)消息
  • 評(píng)論與回復(fù)
登錄后你可以
  • 下載海量資料
  • 學(xué)習(xí)在線課程
  • 觀看技術(shù)視頻
  • 寫文章/發(fā)帖/加入社區(qū)
會(huì)員中心
电子发烧友
开通电子发烧友VIP会员 尊享10大特权
海量资料免费下载
精品直播免费看
优质内容免费畅学
课程9折专享价
創(chuàng)作中心

完善資料讓更多小伙伴認(rèn)識(shí)你,還能領(lǐng)取20積分哦,立即完善>

3天內(nèi)不再提示

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

454398 ? 來源:工程師吳畏 ? 2019-07-30 14:33 ? 次閱讀

設(shè)置Arduino Board

這個(gè)項(xiàng)目使用連接到Arduino Uno的五個(gè)按鈕。使用Arduino為按鈕建立連接,如下圖所示。

項(xiàng)目草圖

在輸入端,我們將有一個(gè)Arduino草圖和一個(gè)Processing草圖。 Arduino草圖將讀取五個(gè)按鈕的狀態(tài),并通過串行通信將其轉(zhuǎn)發(fā)到Processing。 Processing sketch將接收此數(shù)據(jù),并通過OSC(開放式聲音控制)協(xié)議將其轉(zhuǎn)發(fā)給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);

}

設(shè)置ChucK

在輸出端,我們可以使用ChucK從Wekinator接收五個(gè)連續(xù)輸出,并根據(jù)這些輸出發(fā)出聲音。

下載您正在使用的操作系統(tǒng)的FM Synthesis示例。

現(xiàn)在打開終端并轉(zhuǎn)到您放置它的目錄并輸入以下行:

chuck FMSynth_5ContinousOutputs.ck

Chuck將開始收聽Wekinator的輸出并接收輸出,它將改變聲音的音高。

設(shè)置Wekinator

現(xiàn)在打開Wekinator并對(duì)設(shè)置進(jìn)行以下調(diào)整:

將輸入設(shè)置為5并輸出為5

選擇輸出鍵入到所有連續(xù)

Wekinator將從Processing接收五個(gè)輸入,并在訓(xùn)練后將向Chuck發(fā)送五個(gè)不同的輸出。從那里,ChucK將根據(jù)Wekinator輸出產(chǎn)生不同的聲音。

點(diǎn)擊 下一步 按鈕,您將看到此窗口:

按第一個(gè)按鈕,然后單擊 隨機(jī)化 。開始錄制一秒鐘,它將記錄一些樣本。

按第二個(gè)按鈕,然后單擊 隨機(jī)化 的。然后記錄一秒。

同樣,記錄其他三個(gè)按鈕的樣本。

記錄五個(gè)樣本后,單擊在 火車 上訓(xùn)練Wekinator。然后單擊 運(yùn)行 ?,F(xiàn)在當(dāng)您按下按鈕時(shí),程序?qū)⒏鶕?jù)您提供的輸入發(fā)出聲音。

相關(guān)項(xiàng)目

如何構(gòu)建Arduino演講者幾分鐘播放音樂

聲明:本文內(nèi)容及配圖由入駐作者撰寫或者入駐合作網(wǎng)站授權(quán)轉(zhuǎn)載。文章觀點(diǎn)僅代表作者本人,不代表電子發(fā)燒友網(wǎng)立場(chǎng)。文章及其配圖僅供工程師學(xué)習(xí)之用,如有內(nèi)容侵權(quán)或者其他違規(guī)問題,請(qǐng)聯(lián)系本站處理。 舉報(bào)投訴
  • Processing
    +關(guān)注

    關(guān)注

    0

    文章

    10

    瀏覽量

    8976
  • Arduino
    +關(guān)注

    關(guān)注

    188

    文章

    6477

    瀏覽量

    188114
收藏 0人收藏

    評(píng)論

    相關(guān)推薦

    海貝HiBy R1播放器體驗(yàn)

    之前分享過用接入便攜耳放來提升音質(zhì),讓手機(jī)端也能享受HiFi級(jí)的聽感體驗(yàn)。這個(gè)方案對(duì)于沒有數(shù)碼播放器的初燒用戶來說,確實(shí)是種非常高效的方法。 但缺點(diǎn)也是有的,比如歌曲存放需要占用手機(jī)存儲(chǔ)空間,手機(jī)
    的頭像 發(fā)表于 01-24 11:27 ?163次閱讀
    海貝HiBy R1<b class='flag-5'>播放器</b>體驗(yàn)

    畢業(yè)設(shè)計(jì)競(jìng)賽選題推薦 | 嵌入式Linux應(yīng)用之音樂播放器項(xiàng)目實(shí)戰(zhàn)(含文檔及源碼)

    01引言隨著數(shù)字化娛樂日益普及,音樂播放器作為人們生活中不可或缺的一部分,扮演著重要的角色。無論是通勤途中、健身鍛煉還是工作學(xué)習(xí),一個(gè)好用的音樂播放器都能為用戶提供愉悅的音頻體驗(yàn),豐富生活的同時(shí)也
    的頭像 發(fā)表于 12-23 16:50 ?414次閱讀
    畢業(yè)設(shè)計(jì)競(jìng)賽選題推薦 | 嵌入式Linux應(yīng)用之音樂<b class='flag-5'>播放器</b>項(xiàng)目實(shí)戰(zhàn)(含文檔及源碼)

    海貝R1便攜音樂播放器開箱

    作為一個(gè)愛聽音樂打發(fā)時(shí)間的玩家,我已經(jīng)習(xí)慣隨身攜帶一款小巧輕便的音樂播放器,從早期的CD播放器到現(xiàn)在的數(shù)碼播放器,它總能在不經(jīng)意間中給我?guī)砗?jiǎn)單的快樂。不管是逛街等人的時(shí)候,還是工作壓力大的時(shí)候
    的頭像 發(fā)表于 12-09 09:40 ?318次閱讀
    海貝R1便攜音樂<b class='flag-5'>播放器</b>開箱

    AM3354處理wince系統(tǒng)調(diào)playsound播放聲音,有電流雜音怎么解決?

    335板子wince7系統(tǒng)下調(diào)用playsound接口播放wav格式聲音總是有雜音,同一塊板子如果用播放器播放音頻 是沒有雜音的。 同一塊板子wince6系統(tǒng)下調(diào)用playsoun
    發(fā)表于 10-29 06:46

    TLV320AIC3106335板子wince系統(tǒng)下調(diào)用playsound接口播放wav格式聲音總是有雜音,怎么解決?

    TLV320AIC3106335板子wince系統(tǒng)下調(diào)用playsound接口播放wav格式聲音總是有雜音,同一塊板子如果用播放器播放音頻 是沒有雜音的。 我用用飛思卡爾的某個(gè)ce系
    發(fā)表于 10-25 08:00

    變速播放器1和2的區(qū)別

    關(guān)于變速播放器1和2的區(qū)別,由于這里并未明確指出“變速播放器1”和“變速播放器2”具體指的是哪兩款軟件,因此我無法提供這兩款特定軟件之間的對(duì)比。不過,我可以從一般意義上探討變速播放器
    的頭像 發(fā)表于 10-14 09:48 ?291次閱讀

    步步高AB915D DVD播放器維修圖紙

    步步高AB915D DVD播放器采用ZIVA-4.1芯片方案
    發(fā)表于 09-29 10:18 ?0次下載

    為什么好的播放器還要配解碼

    好的播放器之所以需要配備解碼,是因?yàn)橐纛l和視頻文件的編碼和解碼是一個(gè)復(fù)雜的過程,涉及到多種技術(shù)和標(biāo)準(zhǔn)。解碼的作用是將壓縮的音頻和視頻數(shù)據(jù)還原成可以被播放設(shè)備識(shí)別和
    的頭像 發(fā)表于 09-23 18:02 ?1858次閱讀

    數(shù)字播放器和解碼

    數(shù)字播放器和解碼的組合能夠提供更優(yōu)質(zhì)的音頻體驗(yàn)。數(shù)字播放器負(fù)責(zé)處理和傳輸音頻數(shù)據(jù),而解碼則負(fù)責(zé)將這些數(shù)據(jù)轉(zhuǎn)換為高質(zhì)量的模擬信號(hào)。它們的配合可以確保你聽到的音頻既清晰又真實(shí)。
    的頭像 發(fā)表于 09-06 17:35 ?1425次閱讀
    數(shù)字<b class='flag-5'>播放器</b>和解碼<b class='flag-5'>器</b>

    HarmonyOS開發(fā)案例:【視頻播放器

    使用ArkTS語言實(shí)現(xiàn)視頻播放器,主要包括主頁面和視頻播放頁面
    的頭像 發(fā)表于 04-24 14:52 ?1022次閱讀
    HarmonyOS開發(fā)案例:【視頻<b class='flag-5'>播放器</b>】

    HarmonyOS開發(fā)案例:【視頻播放器

    使用ArkTS語言實(shí)現(xiàn)視頻播放器,主要包括主界面和視頻播放界面,
    的頭像 發(fā)表于 04-23 17:25 ?814次閱讀
    HarmonyOS開發(fā)案例:【視頻<b class='flag-5'>播放器</b>】

    HarmonyOS開發(fā)案例:【音樂播放器

    使用ArkTS語言實(shí)現(xiàn)了一個(gè)簡(jiǎn)易的音樂播放器應(yīng)用
    的頭像 發(fā)表于 04-23 15:44 ?1198次閱讀
    HarmonyOS開發(fā)案例:【音樂<b class='flag-5'>播放器</b>】

    HarmonyOS開發(fā)案例:【視頻播放器

    基于video、swiper和slider組件,實(shí)現(xiàn)簡(jiǎn)單的視頻播放器,可支持海報(bào)輪播、視頻播放等功能。
    的頭像 發(fā)表于 04-22 21:06 ?589次閱讀
    HarmonyOS開發(fā)案例:【視頻<b class='flag-5'>播放器</b>】

    用STM32F105的USB做了一個(gè)讀U盤MP3的播放器,為什么聽到的音樂播放速度很快?

    最近用STM32F105的USB做了一個(gè)讀U盤MP3的播放器,使用I2S2_DMA輸出音頻數(shù)據(jù),再使用TAS5711數(shù)字功放進(jìn)行輸出聲音。讀出文件的采樣為44.1khz, I2S也設(shè)置為此采樣率。不知為何,聽到的音樂播放速度很快
    發(fā)表于 04-02 06:52

    鴻蒙開發(fā)-視頻播放器方案

    使用on(\'stateChange\')方法監(jiān)聽狀態(tài)變化。如果應(yīng)用在視頻播放器處于錯(cuò)誤狀態(tài)時(shí)執(zhí)行操作,系統(tǒng)可能會(huì)拋出異?;蛏善渌炊x的行為。 圖1 播放狀態(tài)變化示意圖 當(dāng)播放處于prepared
    發(fā)表于 02-19 17:20

    電子發(fā)燒友

    中國(guó)電子工程師最喜歡的網(wǎng)站

    • 2931785位工程師會(huì)員交流學(xué)習(xí)
    • 獲取您個(gè)性化的科技前沿技術(shù)信息
    • 參加活動(dòng)獲取豐厚的禮品