├── README.md └── Decentralized Music .ipynb /README.md: -------------------------------------------------------------------------------- 1 | # Decentralized_Music 2 | This is the code for "Decentralized Music" By Siraj Raval 3 | 4 | This is part of the School of AI. Find that here www.theschool.ai 5 | -------------------------------------------------------------------------------- /Decentralized Music .ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "metadata": {}, 6 | "source": [ 7 | "## Demo https://github.com/lightningboss/stellar-wind\n", 8 | "\n", 9 | "\n", 10 | "## The Problem with the Online Music Industry\n", 11 | "\n", 12 | "![alt text](https://i.ytimg.com/vi/S7AwryiuTf8/maxresdefault.jpg \"Logo Title Text 1\")\n", 13 | "\n", 14 | "- Artists struggle to make any money off the music they create, even on streaming services. \n", 15 | "- Streaming services allow artists to be independent from a record label\n", 16 | "- However, there's a problem with the amount the artists are actually paid per stream (very little)\n", 17 | "- Each of these streaming services make on average of 1.6 million dollars a day\n", 18 | "- However, the artist only receives 25% of that revenue\n", 19 | "\n", 20 | "![alt text](http://iphoneandroidsolutions.com/wp-content/uploads/2014/12/When-Taylor-Swift-Decided-to-Call-it-Off-with-Spotify-01.jpg \"Logo Title Text 1\")\n", 21 | "\n", 22 | "- Spotify is the biggest competitor in this space but was sued for 1.6 billion dollars (copyright infrigement & withholding compensation from artists)\n", 23 | "- Artists like Taylor Swift and The Beatles have had problems with Spotify\n", 24 | "\n", 25 | "![alt text](https://steemitimages.com/0x0/https://res.cloudinary.com/hpiynhbhq/image/upload/v1516422542/cusmbcg8abpxfqpgkyza.jpg \"Logo Title Text 1\")\n", 26 | "\n", 27 | "\n", 28 | "### Examples of Decentralized Music Apps\n", 29 | "\n", 30 | "### Resound\n", 31 | "\n", 32 | "- A decentralized music marketplace DApp built using Ethereum + IPFS \n", 33 | "- The front-end is built using React/Redux. The backend is Ethereum + IPFS (alawys on, decentralized)\n", 34 | "- This way the web app is uncensorable. A user can use the front-end, but if taken down, can access the backend directly via terminal, metamask, etc. \n", 35 | "- The Ethereum Virtual Machine (EVM) acts as a database for primitive data types and transaction logic.\n", 36 | "- Since gas costs a lot, the author limited the apps usage of the EVM to solely transaction logic\n", 37 | "- Audio files are stored on IPFS, referenced via the ethereum blockchain. \n", 38 | "- The web app is designed to be hosted on a server running an IPFS daemon. It expects artists to pin data to their own servers. \n", 39 | "- It needs moar decentralization! A better scheme to spread out the audio file storage across nodes. \n", 40 | "\n", 41 | "![alt text](https://camo.githubusercontent.com/5139446b2e56d65438ebaac05c645929aed8bb5e/68747470733a2f2f692e696d6775722e636f6d2f396e3864676f6f2e6a7067 \"Logo Title Text 1\")\n", 42 | "\n", 43 | "```javascript\n", 44 | " function createRelease(string _artist, string _title, string _description, string _tracklist, uint64 _price, string _artwork, byte[120][] _files) public {\n", 45 | " uint id = releases.length;\n", 46 | " releases.push(Release(id, msg.sender, _artist, _title, _description, _tracklist, _price, _artwork, _files));\n", 47 | " artistReleases[msg.sender].push(id);\n", 48 | " NewRelease(msg.sender, _title, _artist);\n", 49 | " }\n", 50 | "```\n", 51 | "\n", 52 | "### ferment\n", 53 | "\n", 54 | "![alt text](https://github.com/fermentation/ferment/raw/master/assets/ferment-screenshot-0.0.0.jpg \"Logo Title Text 1\")\n", 55 | "\n", 56 | "- A peer-to-peer audio publishing and streaming application. Think SoundCloud or Spotify, but entirely decentralized and free.\n", 57 | "- Uses a peer-to-peer gossip protocol called Secure Scuttlebutt. \n", 58 | "- Secure Scuttlebutt is a database protocol for unforgeable append-only message feeds.\n", 59 | "- \"Unforgeable\" means that only the owner of a feed can update that feed, as enforced by digital signing (see Security properties).\n", 60 | "\n", 61 | "![alt text](https://ssbc.github.io/docs/gossip-graph1.png \"Logo Title Text 1\")\n", 62 | "\n", 63 | "- Scuttlebot forms a global cryptographic social network with its peers. Each user is identified by a public key, and publishes a log of signed messages, which other users follow socially.\n", 64 | "- No central server and no single point of failure. \n", 65 | "- Everyone on the network is a server, with a copy of all of their friends and their friend's friends data. \n", 66 | "- Peers gossip with other peers to find out if any of their shared contacts have any new posts and share them. \n", 67 | "\n", 68 | "![alt text](https://staltz.com/img/ssb-account.svg \"Logo Title Text 1\")\n", 69 | "\n", 70 | "- By gossip, 'cryptographically prove everything they've said since the last time you heard from them' is meant\n", 71 | "- Finding peers across the complex topography of the internet is pretty difficult though. \n", 72 | "- Pub servers are the solution!\n", 73 | "- Pub servers act as gossip hubs where information can be shared across networks. \n", 74 | "- A pub is just an ordinary Ferment peer that has a publicly accessible IP address and can be remotely connected to on demand.\n", 75 | "- The actual audio files are just torrents (a special variant called webtorrent that works over WebRTC).\n", 76 | "\n", 77 | "![alt text](https://camo.githubusercontent.com/2a5ecae93025ab7061d187a4340e6d4c25111386/68747470733a2f2f6c7574696d2e6370792e72652f70714b6d335135532e706e67 \"Logo Title Text 1\")\n", 78 | "\n", 79 | "- The SSB message contains a reference to its magnet url, and you seed the file to other ferment peers.\n", 80 | "- Whenever a users listens to something in Ferment, theu start seeding that file with other peers. \n", 81 | "\n", 82 | "```javascript\n", 83 | "function TorrentStatus (infoHash) {\n", 84 | " var result = MutantStruct({\n", 85 | " progress: Value(0),\n", 86 | " downloadSpeed: Value(0, {defaultValue: 0}),\n", 87 | " uploadSpeed: Value(0, {defaultValue: 0}),\n", 88 | " numPeers: Value(0),\n", 89 | " complete: Value(0),\n", 90 | " uploaded: Value(0),\n", 91 | " downloaded: Value(0),\n", 92 | " seeding: Value(false),\n", 93 | " loading: Value(false),\n", 94 | " saving: Value(false)\n", 95 | " })\n", 96 | "\n", 97 | "```\n", 98 | "\n", 99 | "### Opus Foundation\n", 100 | "\n", 101 | "![alt text](https://i.imgur.com/6Nr7YI9.png \"Logo Title Text 1\")\n", 102 | "\n", 103 | "- A decentralized music streaming platform where artists get paid 90% of revenue\n", 104 | "- Leverages the speed and redundancy of IPFS\n", 105 | "- Claims to scale and deliver thousands of tracks per second in a fully decentralized manner. \n", 106 | "- Encrypts music tracks on the fly and stores the encrypted music files permanently on the IPFS swarm.\n", 107 | "- Only the decryption keys, and file hashes, are saved immutably on the Opus smart contract. \n", 108 | "- By only storing the decryption keys and reference hashes, they can facilitate a number of novel features such as file ownership, trade, and full decentralization. \n", 109 | "\n", 110 | "![alt text](https://i.imgur.com/JYyMb5L.png \"Logo Title Text 1\")\n", 111 | "\n", 112 | "- Artists can monetize their content by selling permanent access to their IPFS music files and decryption keys directly to a fan’s Ethereum contract, without any middleman. \n", 113 | "- Exciting bit - Plan to implement additional governance mechanisms such as a Opus DAO (Decentralized Autonomous Organization) treasury funded from a small percentage of each sale, and an artist bounty system that allows artists to pay a small amount for people to share their tracks.\n", 114 | "- IPFS enables the Opus smart contract to index individual music track onto a permanent and immutable hash.\n", 115 | "- Storage layer is IPFS. Logic layer needed for artist compensation, securing ownership + trade of songs. \n", 116 | "- Etherum is that logic layer. Artists and fans can rest assured 100% of the payments are delivered to the artists transparently, immutably and without intermediaries taking large chunks of revenue. \n", 117 | "- Artists can also rest assured that their revenue stream will not change at the whim of corporate greed.\n", 118 | "\n", 119 | "![alt text](https://cdn-images-1.medium.com/max/1600/1*JzAjawXPCYagWWXcMQj8-g.png \"Logo Title Text 1\")\n", 120 | "\n", 121 | "```javascript\n", 122 | "playSong: (licenseAddress)=>{\n", 123 | "App.loadPlayingToPage(licenseAddress);\n", 124 | "var Opus;\n", 125 | "App.getSongFromAddress(licenseAddress).then(function(instance) {\n", 126 | "Opus = instance;\n", 127 | "return Opus.requestKeyandHash.call({from: account});\n", 128 | "}).then((res) => {\n", 129 | "var _key = res[0];\n", 130 | "var _hash = res[1];\n", 131 | "var _url = App.gatewayUrlfromHash(_hash);\n", 132 | "var _player = document.getElementById(\"audioplayer\");\n", 133 | "_player.src = _url;\n", 134 | "App.playbackwithKey(licenceAddress, _key);\n", 135 | "}).catch((e) => {\n", 136 | "console.log(e);\n", 137 | "})\n", 138 | "},\n", 139 | "\n", 140 | "```\n", 141 | "\n", 142 | "## How does Stellar Work? \n", 143 | "\n", 144 | "![alt text](https://www.stellar.org/wp-content/uploads/2016/06/Stellar-Ecosystem-v031.png \"Logo Title Text 1\")\n", 145 | "\n", 146 | "- Created by Dr. David Mazières, a professor of computer science at Stanford University.\n", 147 | "- one of Stellar’s major missions is to help the unbanked become bankable. \n", 148 | "- Aimed at tackling scalability + speed problems of Bitcoin\n", 149 | "\n", 150 | "![alt text](https://www.stellar.org/wp-content/uploads/2014/06/home0516-preview3.png \"Logo Title Text 1\")\n", 151 | "\n", 152 | "- How to maintain consensus among nodes in a very fast AND secure system? Well, we def can't use proof of work.\n", 153 | "- Federation is used! This is just a group of trusted nodes that can decide to trust other nodes and thereby add to consensus. \n", 154 | "- Any entity can set up and run a server, but that doesn’t mean that everyone else is going to trust that entity.\n", 155 | "- Each node communicates with one another and accepts verification and reaches consensus every 2–5 seconds with other trusted peers. \n", 156 | "\n", 157 | "![alt text](https://image.slidesharecdn.com/stellar-presentation-final-140819114335-phpapp01/95/stellar-protocol-what-is-stellar-and-why-it-matters-11-638.jpg?cb=1408448727 \"Logo Title Text 1\")\n", 158 | "\n", 159 | "- Eventually you have an entire network of peers that trust each other mutually through other trusted peers. \n", 160 | "- This is how the SCP forms consensus about who can actually form consensus in the first place without creating a central body that owns it all. \n", 161 | "- The end result is completely synced ledger every 2–5 seconds.\n", 162 | "- Basically, numerous nodes across the network vote in order to create consensus, and the voting gives more bias towards trusted nodes.\n", 163 | "\n", 164 | "![alt text](https://novicedock.com/wp-content/uploads/2018/01/stellar-consensus-protocol.png \"Logo Title Text 1\")\n", 165 | "\n", 166 | "- Also uses a Decentralized Excxhange (SDEX) \n", 167 | "- SDEX allows currencies to be traded and transferred across borders. \n", 168 | "- Currently, in order for a bank to send money to another bank, they have to use a communications network that works in their country (like ACH or SWIFT) or use something like Western Union or another courier service.\n", 169 | "- With Stellar Exchange, multiple currencies can be actively traded by either the bank themselves or a market maker (middleman) directly on the exchange.\n", 170 | "\n", 171 | "![alt text](https://i.redd.it/9yxpuykhblhz.png \"Logo Title Text 1\")\n", 172 | "\n", 173 | "- The Stellar network uses lumens. A lumen is a native asset on the Stellar network. \n", 174 | "- Lumens can be used as a bridge currency if there aren’t any buy/sell offers on the exchange for the selected currencies.\n", 175 | "- Think of lumens as an intermediate currency that is trusted by both parties to transfer value from one asset to another.\n", 176 | "- Someone recently was selling shares of his goat farm in the Dominican Republic on the SDEX.\n", 177 | "- There’s a secondary usage to lumens as well — they serve as an anti-spam mechanism because each transaction on the lumen network has a minor fee. This helps to mitigate DoS (Denial of Service) attacks by limiting the volume of fake transactions that try to flood the system.\n", 178 | "\n", 179 | "![alt text](https://www.stellar.org/wp-content/uploads/2015/04/properties-no-margin1.png \"Logo Title Text 1\")\n", 180 | "\n", 181 | "## Architecture\n", 182 | "\n", 183 | "- Stellar Wind transforms the activity on the Stellar Network into harmonic musical art by mapping every transaction to a musical note depending on the relative height of the transaction amount.\n", 184 | "- It is intended to be kept open in a browser tab to listen to for relaxation, coding or any other activity requiring calmness and focus.\n", 185 | "- The data for Stellar Wind to compose music is streamed from the Horizon API server.\n", 186 | "- It captures all occurring transactions and stores all non zero amounts from operations in the network.\n", 187 | "- Those amounts are taken off a queue in regular intervals and used as normalized inputs for the music composition.\n", 188 | "- Stellar Wind uses tone.js to play music. To create interesting melodies, notes are picked from a C-minor pentatonic scale with an added A flat. (that adds some interesting colors) ;\n", 189 | "\n", 190 | "## Demo time! " 191 | ] 192 | }, 193 | { 194 | "cell_type": "code", 195 | "execution_count": null, 196 | "metadata": {}, 197 | "outputs": [], 198 | "source": [] 199 | } 200 | ], 201 | "metadata": { 202 | "kernelspec": { 203 | "display_name": "Python 3", 204 | "language": "python", 205 | "name": "python3" 206 | }, 207 | "language_info": { 208 | "codemirror_mode": { 209 | "name": "ipython", 210 | "version": 3 211 | }, 212 | "file_extension": ".py", 213 | "mimetype": "text/x-python", 214 | "name": "python", 215 | "nbconvert_exporter": "python", 216 | "pygments_lexer": "ipython3", 217 | "version": "3.6.3" 218 | } 219 | }, 220 | "nbformat": 4, 221 | "nbformat_minor": 2 222 | } 223 | --------------------------------------------------------------------------------