1 // nova server, audio bus 2 // Copyright (C) 2009 Tim Blechmann 3 // 4 // This program is free software; you can redistribute it and/or modify 5 // it under the terms of the GNU General Public License as published by 6 // the Free Software Foundation; either version 2 of the License, or 7 // (at your option) any later version. 8 // 9 // This program is distributed in the hope that it will be useful, 10 // but WITHOUT ANY WARRANTY; without even the implied warranty of 11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 // GNU General Public License for more details. 13 // 14 // You should have received a copy of the GNU General Public License 15 // along with this program; see the file COPYING. If not, write to 16 // the Free Software Foundation, Inc., 59 Temple Place - Suite 330, 17 // Boston, MA 02111-1307, USA. 18 19 #pragma once 20 21 #include <cstdint> 22 #include "sample_types.hpp" 23 24 #include "malloc_aligned.hpp" 25 #include "nova-tt/rw_spinlock.hpp" 26 27 namespace nova { 28 29 class audio_bus_manager { 30 typedef std::uint16_t uint16_t; 31 32 public: 33 audio_bus_manager(void) = default; 34 audio_bus_manager(audio_bus_manager const&) = delete; 35 audio_bus_manager& operator=(audio_bus_manager const&) = delete; 36 initialize(uint16_t c,uint16_t b)37 void initialize(uint16_t c, uint16_t b) { 38 count = c; 39 blocksize = b; 40 buffers = calloc_aligned<sample>(count * blocksize); 41 locks = new padded_rw_spinlock[count]; 42 } 43 ~audio_bus_manager(void)44 ~audio_bus_manager(void) { 45 free_aligned(buffers); 46 delete[] locks; 47 } 48 acquire_bus(uint16_t index)49 sample* acquire_bus(uint16_t index) { 50 locks[index].lock(); 51 return get_bus(index); 52 } 53 get_bus(uint16_t index)54 sample* get_bus(uint16_t index) { 55 assert(index < count); 56 return buffers + index * blocksize; 57 } 58 release_bus(uint16_t index)59 void release_bus(uint16_t index) { locks[index].unlock(); } 60 61 private: 62 friend class sc_plugin_interface; 63 64 uint16_t count = 0; 65 uint16_t blocksize = 0; 66 sample* buffers = nullptr; 67 padded_rw_spinlock* locks = nullptr; 68 }; 69 70 } /* namespace nova */ 71