Phonon Republic ︰ MusicPi 【音樂派】為什麼?

列子‧湯問篇

高山流水

伯牙善鼓琴,鍾子期善聽。伯牙鼓琴,志在登高山。鍾子期曰:「善哉!峨峨兮若泰山!」志在流水。鍾子期曰:「善哉!洋洋兮若江河!」伯牙所念,鍾子期必得之。伯牙游於泰山之陰,卒逢暴雨,止於巖下;心悲,乃援琴而鼓之。初為霖雨之操,更造崩山之音。曲每奏,鍾子期輒窮其趣。伯牙乃舍琴而嘆曰:「善哉,善哉 ,子之聽夫!志想象猶吾心也。吾於何逃聲哉?」

 

贈花卿‧杜甫

錦城絲管日紛紛,
半入江風半入雲。
此曲祇應天上有,
人間能有幾回聞?

高山流水之志,天上人間之曲,

音樂

音樂,廣義而言,就是指任何以聲音組成的藝術。英文Music一詞源於古希臘語的μουσική(mousike),意即繆斯(muse)女神的藝術。而中文的音樂二字,許慎《說文解字》解釋為「音,聲也。生於心,有節於外,謂之音。」認為音樂和聲音的區別,在於音樂需要透過人心去想像和創造。音樂可分為創作演奏聆聽三個過程,在不同文化和社會,對於音樂的過程及其重要性都有不同的理解。例如在西非鼓樂里,每個人皆是參與者,人們不會區分作曲者 、演奏者和聆聽者的身份。

至於何謂聲音、噪音和音樂的區別,沒有公認的標準。因為音樂和數學物理相關,歐洲自古希臘時代開始,有人論述樂理。在西方樂理中,音樂的主要元素有音高(或聲音的頻率)、節奏音色。不同的音高重疊形成和聲,音高依據節奏進行成為旋律,常用的音高形成音階調性,規律性的強拍和弱拍形成節拍,拍子的快慢構成速度。但近代有不少音樂家不認同傳統的理解,例如二十世紀美國作曲家約翰·凱吉認為任何聲音和靜默皆是音樂。音樂可以分為不同種類,但每種種類的區別常常是含糊和具爭議的。

音樂可以用樂譜描述,依據樂譜演奏,但也有不少音樂類型如民歌爵士樂是由演奏者即興創作的。樂譜作為一種符號的語言,只能描述聲音的屬性或指示演奏所需的技巧,卻無法記錄聲音本身。因此在錄音技術出現之前,欣賞音樂必需現場聆聽,或自己親身參與演奏。傳統上欣賞音樂有特定的場所,從古時的宮庭、教堂、廟宇到今天的音樂廳、酒吧等等。十九世紀末,留聲機的發明令聲音可以記錄和複製,改變了欣賞音樂的模式,一般認為錄音技術和大眾媒體是流行音樂形成的主要因素。現在人們可以在家中聆聽唱片音樂錄像,透過無線電收音機電視接收聲音的訊號,也可以攜帶隨身聽在任何一個地方聆聽音樂。

演奏音樂需要透過歌唱樂器。廣義的樂器包括一切可以發出聲音的工具,在石器時代人們已經開始製作原始的樂器。今天電腦和不少電子音樂產品可以透過MIDI製作音樂。

音樂是一種需要學習的技能,而在不少國家的基礎教育中包括有音樂課,而一些音樂學院則提供專業的音樂教育。音樂學是一個歷史的科學的研究音樂的廣闊領域,其中包括音樂理論音樂史。另外自十九世紀末開始有民族音樂學,研究各地不同的音樂文化。

800px-huizong_1102

北宋宋徽宗所繪古琴畫作

振奮人心,打動心靈,是聲子的舞蹈、靈魂的語言。所以音樂沒有國界,音符沒有疆域,能夠溝通四方之人,能夠和諧大地萬物。故為美育的重要環節。若是缺少適當的設備環境,將要如何欣賞呢?彷彿炒菜沒加鹽,雖非不能吃也,或許淡而無味的吧!音樂派就是那鹽,聆聽音樂必要的軟硬體工具系統!!

 

 

 

 

 

 

 

 

 

 

Phonon Republic ︰ phononPi 【聲子派】是何物?

縱使『理念』之『純粹』︰

之前我們在《走進音樂世界!!》一文中 介紹過英國劍橋大學 Dr . Sam Aaron 博士,Sonic π 的作者,他的『音樂程式』理念是︰

那兒並沒有錯誤

There are no mistakes
Before we start, let me just give you one piece of advice I’ve learned over my years of live coding with music – there are no mistakes, only opportunities. This is something I’ve often heard in relation to jazz but it works equally well with live coding. No matter how experienced you are – from a complete beginner to a seasoned Algoraver, you’ll run some code that has a completely unexpected outcome. It might sound insanely cool – in which case run with it. However, it might sound totally jarring and out of place. It doesn’t matter that it happened – what matters is what you do next with it. Take the sound, manipulate it and morph it into something awesome. The crowd will go wild.

現今『 Sonic π 』2.0 版已經正式發布,據聞將用於英國 KS3 ── 十一歲到十三歲 ── 的『程式語言』教育之中。它的主要『學習目標』是︰

Computer Science concepts:

Sequencing
Debugging
Iteration
Conditionals
Data Structures
Algorithms
Functions
Concurrency

計算機科學概念

編序
除錯
疊代
條件轉移
資料結構
演算法
函式
並行性

Sonic Pi(在 raspberrypi)_069

學習』需是要『溫故知新』,須能夠『專心致志』,方才可『精博通達』。就讓我們藉著『音樂』去悠遊『程式』一番,再次發現自然裡『聲音的宇宙』。

─── 摘自《 Sonic π 知音?!

Sonic Pi Essentials

Learn to code musical masterpieces with the creator of Sonic Pi in our best Essentials e-book yet!

sonicpi

Sam Aaron, the creator of Sonic Pi, has written this book to complement the software’s built-in tutorial and to help you jump-start your live-coding career. The book is packed with fun, instantly rewarding examples designed to highlight many of the amazing things Sonic Pi enables you to do. By the time you’ve finished you’ll be able to code up some phat bass, sparkling synth leads and start practicing for your first live-coding gig…

Live code and craft amazing sounds across 10 chapters, including:

  • Master live loops
  • Build drum breaks
  • Compose your own melodies
  • Make random riffs and loops
  • Learn to shape and sculpt sounds
  • and much, much more…

 

,實際未必能創造『需求』 Needs and Wants 也。若說『科技』來自於『人性』── 需要與欲望 ──,總也得『正名』乎??故說此『聲子派』之要求耶!!豈能不為『聲』之於『耳』而立傳呢︰

聲子

聲子Phonon)是晶體晶體結構集體激發的準粒子化學勢為零 ,服從玻色-愛因斯坦統計,是一種玻色子。聲子本身並不具有物理動量,但是攜帶有準動量 ℏ q {\displaystyle \hbar \mathbf {q} } \hbar \mathbf{q},並具有能量 ℏ ω {\displaystyle \hbar \omega } \hbar \omega(其中 ℏ {\displaystyle \hbar } \hbar 為約化普朗克常數)。根據南部-戈德斯通定理,任何連續性整體對稱性的自發破缺,必然對應一個零質量的玻色子。聲子就是平移對稱性被晶格的點陣結構自發破缺以後對應的玻色子。聲子與電子的相互作用,是導致BCS超導的關鍵機制。

Phonon

In physics, a phonon is a collective excitation in a periodic, elastic arrangement of atoms or molecules in condensed matter, like solids and some liquids. Often designated a quasiparticle,[1] it represents an excited state in the quantum mechanical quantization of the modes of vibrations of elastic structures of interacting particles.

Phonons play a major role in many of the physical properties of condensed matter, like thermal conductivity and electrical conductivity. The study of phonons is an important part of condensed matter physics.

The concept of phonons was introduced in 1932 by Soviet physicist Igor Tamm. The name phonon comes from the Greek word φωνή (phonē), which translates to sound or voice because long-wavelength phonons give rise to sound. Shorter-wavelength higher-frequency phonons are responsible for the majority of the thermal capacity of solids.

Definition

A phonon is a quantum mechanical description of an elementary vibrational motion in which a lattice of atoms or molecules uniformly oscillates at a single frequency.[2] In classical mechanics this designates a normal mode of vibration. Normal modes are important because any arbitrary lattice vibration can be considered to be a superposition of these elementary vibration modes (cf. Fourier analysis). While normal modes are wave-like phenomena in classical mechanics, phonons have particle-like properties too, in a way related to the wave–particle duality of quantum mechanics.

 

然而『正名』之事,不必談及 □ □ 硬體在內 inside ,跑的是 ○ ○ 作業系統 OS 。但考之以實際功能、效用而已矣。因是『聲子派』之名義乃是 Sonic Pi 能運行良好的聲音環境;至少可及於 Pure Data 以及 jackd2 種種應用的軟硬體系統。

 

 

 

 

 

 

 

 

 

 

Phonon Republic ︰【聲子共和國】之緣起

兩年前之夏日某夜,幾位朋友聚會。當時英國劍橋的 Dr Sam Aaron 博士寫作 Sonic π 【※ 參閱《走進音樂世界!!》】剛發行沒多久。大家聊起了這件事︰

讓電腦科學變成聽得到的。

其中玩『聲音合成器』的一位朋友說︰

樹莓派聲音太差, Sonic π 產出的結果,簡直慘不忍聞。

彷彿跂礄之友並不同意這個論點。他講︰

現今已有 I2S DAC 聲卡,假以時日自然迎刃而解。

其他人也加入戰局,儼然成了論

《樹莓派與可聽性之關係》

的研討會哩。

似乎那時作者的態度在『兩可』之間,或較偏向跂礄之友的說法。也許一時口快,言道︰若做出來了,將為它命名,替它寫傳。誰知日前人將東西給拿來了,還不只一種,分明三樣,問着立名作傳之事。果真古人講的好

飯可以多吃,話切莫多說。

既然言已出口,總得說到做到。苦惱之餘,偶憶『香蕉共和國Banana Republic 傳奇事蹟。何不借法說法,將此產品系列命之為

Phonon Republic  【聲子共和國】

。其支系有

‧ phononPi 【聲子派】

‧ musicPi 【音樂派】

‧ midiPi 【美的派】

 

鋪陳一篇虛實交錯之品牌創生故事耶☆

 

 

 

 

 

 

 

 

 

 

樹莓派聲音︰ dtoverlay

去年初樹莓派官方決定引入 device trees 、 dtparam 以及 dtoverlay  管理裝置資源、模組載入和參數設定。那時作者曾寫一系列文本,介紹 /boot/config.txt 的變遷與 device trees dtc 之編譯/解碼︰

1_180504_2

清代‧居廉‧ 扶桑

山海經‧海外東經

帝命豎亥步,自東極至於西極,五億十選九千八百步。豎亥右手把筭,左手指青丘北。…

黑齒國在其北,為人黑,食稻啖蛇,一赤一青,在其旁。…

下有湯谷。湯谷上有扶桑,十日所浴,在黑齒北。居水中,有大木,九日居下枝,一日居上枝。

參天大木,始於生,終至成。如是遂有日居焉?而後才能水木榮諸??此方謂『扶桑』── 意在春蠶吐絲哉 ── !!

如果用錯了鑰匙,再簡單的鎖也打不開;就算撬開了鎖,難到事物必然一樣的嗎??

曾經人們希望『○』,然後冀盼『□』,接續期待『☆』,祇不濄人類的『科學』也許也僅能專著於『眼見』,那個『精神』卻日漸地虛無飄渺了吧!

現象顯示『意義的消逝』和『快樂之伏藏』是『相同的一面』,那麼所謂『背面』又到底有些什麼的呢?宛如『天下是天下人的天下』,任誰都無法管之天下吧!怎就不該即時行樂的呢?麻煩在於『無所得故』,言及社會未來,世代傳承……。千百萬年之歷史總歸一詞 ── 終究人性 ──!?

無有』沒法整理,『眾集』不耐其繁,『 Know-How 』多了,或許必將會產生『物以類聚』── 物件描述法 ── 的『 What’s What 』之群分的事!!這當真就是『 Device Tree 』自將之興起的道理嗎??

───《大樹底下好乘涼 ︰ 《開場白》

 

滄海桑田不必久,人世變化未必慢。如今 devicetree.org 已換新妝︰

Welcome to devicetree.org

If you are looking for the devicetree specification you’ve come to the right place!

Devicetree.org is a community effort by many companies and individuals to facilitate the future evolution of the Devicetree Standard.

The devicetree is a data structure for describing hardware. Rather than hard coding every detail of a device into an operating system, many aspects of the hardware can be described in a data structure that is passed to the operating system at boot time. The devicetree is used by OpenFirmware, OpenPOWER Abstraction Layer (OPAL), Power Architecture Platform Requirements (PAPR) and in the standalone Flattened Device Tree (FDT) form.

The devicetree specification provides a full technical description of the devicetree data format and best practices.

The devicetree.org technical steering commitee is the group responsible for developing, managing and promoting the devicetree specification. However, everyone is encouraged to get involved and yes there is a GitHub project too! Further information about the devicetree standard and membership opportunities can be found throughout this website.

 

也發行了新版規格書︰

dtspec

The Devicetree Specification

Device Tree Specification Release 0.1
This is the first formal baseline release of the device tree specification. This document is a first iteration of ePAPR 1.1 and picks up where it left off in 2012.

The next release, v1.0 is planned for the end of August, 2016, which will be up to date with current core DT bindings used by the Linux kernel.

If you would like to get involved please fetch the document source from GitHub and join the mailing list. Comments and patches are welcome at any time!

A second major release is planned for December 2016 to cover new features. The timeline for planned future releases are shown here and you can always find the latest release, as well as all older releases, in our GitHub repository: Devicetree Specification release repository

 

終究得與時偕行乎!!??

樹莓派上 I2S 聲卡設定,還請參照︰

Device Trees, overlays, and parameters

Raspberry Pi’s latest kernels and firmware, including Raspbian and NOOBS releases, now by default use Device Tree (DT) to manage some resource allocation and module loading. This change is to alleviate the problem of multiple drivers contending for system resources, and to allow HAT modules to be auto-configured.

The current implementation is not a pure Device Tree system – there is still board support code that creates some platform devices – but the external interfaces (I2C, I2S, SPI), and the audio devices that use them, must now be instantiated using a Device Tree Blob (DTB) passed to the kernel by the loader (start.elf).

The main impact of using Device Tree is to change from everything on, relying on module blacklisting to manage contention, to everything off unless requested by the DTB. In order to continue to use external interfaces and the peripherals that attach to them, you will need to add some new settings to your config.txt. Full details are given in Part 3, but these are a few examples:

# Uncomment some or all of these to enable the optional hardware interfaces
#dtparam=i2c_arm=on
#dtparam=i2s=on
#dtparam=spi=on

# Uncomment one of these lines to enable an audio interface
#dtoverlay=hifiberry-amp
#dtoverlay=hifiberry-dac
#dtoverlay=hifiberry-dacplus
#dtoverlay=hifiberry-digi
#dtoverlay=iqaudio-dac
#dtoverlay=iqaudio-dacplus
#dtoverlay=audioinjector-wm8731-audio

# Uncomment this to enable the lirc-rpi module
#dtoverlay=lirc-rpi

# Uncomment this to override the defaults for the lirc-rpi module
#dtparam=gpio_out_pin=16
#dtparam=gpio_in_pin=17
#dtparam=gpio_in_pull=down

 

各個 dtoverlay 之參數與詳細說明,務須仔細閱讀︰

pi@raspberrypi:/boot/overlays $ more README 
Introduction
============

This directory contains Device Tree overlays. Device Tree makes it possible
to support many hardware configurations with a single kernel and without the
need to explicitly load or blacklist kernel modules. Note that this isn't a
"pure" Device Tree configuration (c.f. MACH_BCM2835) - some on-board devices
are still configured by the board support code, but the intention is to
eventually reach that goal.

On Raspberry Pi, Device Tree usage is controlled from /boot/config.txt. By
default, the Raspberry Pi kernel boots with device tree enabled. You can
completely disable DT usage (for now) by adding:

    device_tree=

to your config.txt, which should cause your Pi to revert to the old way of
doing things after a reboot.

In /boot you will find a .dtb for each base platform. This describes the
hardware that is part of the Raspberry Pi board. The loader (start.elf and its
siblings) selects the .dtb file appropriate for the platform by name, and reads
it into memory. At this point, all of the optional interfaces (i2c, i2s, spi)
--More--(1%)

 

 

 

 

 

 

 

 

 

 

樹莓派聲音︰ I2S

什麼是 I2S 呢?維基百科詞條這麼講︰

I²S

I²SI2S英語:Inter-IC SoundIntegrated Interchip Sound)是IC間傳輸數位音訊資料的一種介面標準,採用序列的方式傳輸2組(左右聲道)資料。I2S常被使用在傳送CDPCM音訊資料到CD播放器的DAC中。由於I2S將資料訊號和時脈訊號分開傳送,它的抖動jitter)失真十分地小。

實有來歷的哩︰

History

This standard was introduced in 1986 by Philips (now NXP) and was last revised in 1996.[1]

Details

The I²S protocol outlines one specific type of PCM digital audio communication with defined parameters outlined in the Philips specification.

The bit clock pulses once for each discrete bit of data on the data lines. The bit clock frequency is the product of the sample rate, the number of bits per channel and the number of channels. So, for example, CD Audio with a sample frequency of 44.1 kHz, with 16 bits of precision and two channels (stereo) has a bit clock frequency of:

44.1 kHz × 16 × 2 = 1.4112 MHz

The word select clock lets the device know whether channel 1 or channel 2 is currently being sent, since I²S allows two channels to be sent on the same data line. For stereo material, the I²S specification states that left audio is transmitted on the low cycle of the word select clock and the right channel is transmitted on the high cycle. The word select clock is a 50% duty-cycle signal that has the same frequency as the sample frequency.

Data are encoded in two’s complement with the MSB (most significant bit) first.[1]:2

The bus consists of at least three lines:

  1. Bit clock line
  2. Word clock line – also called word select (WS) or left right clock (LRCLK)
  3. At least one multiplexed data line

It may also include the following lines:

  1. Master clock (typical 256 x LRCLK)
  2. A multiplexed data line for upload

In audio equipment the I²S sometimes forms an external link between the CD transport and a separate DAC box, contrary to purely internal connection within one player box. This may form an alternative to the commonly used AES/EBU or Toslink or S/PDIF standards. There is no standard interconnecting cable for this application. Some manufacturers provide simply three BNC connectors, an 8P8C (“RJ45”) socket or a DE-9 connector. Others like Audio Alchemy (now defunct) used DIN connectors.

樹莓派之 I2S 規格在 BROADCOM

 

DataSheet 的第一百一拾九頁。

接法及接腳請參照

archphile-logo-minimal

Introduction to Archphile

Summary:
Archphile is an Archlinux ARM/MPD based distribution for Raspberry Pi (B, B+ and 2), Udoo Quad (also dual with some extra steps)  and Cubox-i targeted to users with USB and I2S Dacs.

Some of its features:

  • support for USB and I2S Dacs
  • recompiled mpd 0.19.13 (mpd-archphile) based on mpd-light from AUR  – niceness is set to -16 and lots of mpd features are disabled in each version (press mpd -V for more info)
  • ympd web interface
  • usb disk/flash automounting using udevil.
  • upnp/dlna support using upmpdcli
  • Airplay/shairport using shairport-sync
  • dchp enabled by default
  • reachable with url http://archphile.local if zeroconf is enabled. Windows users please download this package to enable. In any other situation you can find the ip from your router
  • samba/cifs/nfs support – you have configure /etc/fstab  according to your own needs  by modifying the sample lines
  • default credentials:

username: root
password: archphile

  • various webradios based on Volumio github repository.
  • mixer is disabled by default. Use your amp to change the volume level. Ensure that system level is set to 100% using alsamixer command.

 

之說明文件︰

I2S Dacs and the Raspberry Pi

Let’s start with some nice schematics  showing the connections needed:

– Raspberry Pi model B

raspberrypi_i2s_p5-1

 

raspberrypi_i2s_p5_2

 

– Rasbperry Pi model B+ and model 2

raspberrypi_B_plus_i2s_1

 

raspberrypi_B_plus_i2s_2

 

有興趣讀寫驅動程式者,請到這來︰

Linux/sound/soc/bcm/bcm2835-i2s.c

1 /*
2 * ALSA SoC I2S Audio Layer for Broadcom BCM2835 SoC
3 *
4 * Author: Florian Meier <florian.meier@koalo.de>
5 * Copyright 2013
6 *
7 * Based on
8 * Raspberry Pi PCM I2S ALSA Driver
9 * Copyright (c) by Phil Poole 2013
10 *
11 * ALSA SoC I2S (McBSP) Audio Layer for TI DAVINCI processor
12 * Vladimir Barinov, <vbarinov@embeddedalley.com>
13 * Copyright (C) 2007 MontaVista Software, Inc., <source@mvista.com>
14 *
15 * OMAP ALSA SoC DAI driver using McBSP port
16 * Copyright (C) 2008 Nokia Corporation
17 * Contact: Jarkko Nikula <jarkko.nikula@bitmer.com>
18 * Peter Ujfalusi <peter.ujfalusi@ti.com>
19 *
20 * Freescale SSI ALSA SoC Digital Audio Interface (DAI) driver
21 * Author: Timur Tabi <timur@freescale.com>
22 * Copyright 2007-2010 Freescale Semiconductor, Inc.
23 *
24 * This program is free software; you can redistribute it and/or
25 * modify it under the terms of the GNU General Public License
26 * version 2 as published by the Free Software Foundation.
27 *
28 * This program is distributed in the hope that it will be useful, but
29 * WITHOUT ANY WARRANTY; without even the implied warranty of
30 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
31 * General Public License for more details.
32 */
33