220 26134 <CANh-dX=R4Oa0OPZSrL7c9PXGyAdvM2CCBdP9C+h--N4Vt-J=9g@mail.gmail.com> article
Path: news.gmane.org!not-for-mail
From: "'Jeffrey Yasskin' via ISO C++ Standard - Future Proposals" <std-proposals@isocpp.org>
Newsgroups: gmane.comp.lang.c++.isocpp.proposals
Subject: Re: Any interest to adding audio support to the std library?
Date: Fri, 3 Jun 2016 08:43:21 -0700
Lines: 264
Approved: news@gmane.org
Message-ID: <CANh-dX=R4Oa0OPZSrL7c9PXGyAdvM2CCBdP9C+h--N4Vt-J=9g@mail.gmail.com>
References: <f490fd21-cf07-4d7b-8936-c71c97a1ab9d@isocpp.org>
Reply-To: std-proposals@isocpp.org
NNTP-Posting-Host: plane.gmane.org
Mime-Version: 1.0
Content-Type: text/plain; charset=UTF-8
X-Trace: ger.gmane.org 1464968626 22796 80.91.229.3 (3 Jun 2016 15:43:46 GMT)
X-Complaints-To: usenet@ger.gmane.org
NNTP-Posting-Date: Fri, 3 Jun 2016 15:43:46 +0000 (UTC)
To: std-proposals@isocpp.org
Original-X-From: std-proposals+bncBDDM34EO6QDRBLOLY25AKGQE56CCUZA@isocpp.org Fri Jun 03 17:43:46 2016
Return-path: <std-proposals+bncBDDM34EO6QDRBLOLY25AKGQE56CCUZA@isocpp.org>
Envelope-to: gclcip-std-proposals@m.gmane.org
Original-Received: from mail-pa0-f70.google.com ([209.85.220.70])
	by plane.gmane.org with esmtp (Exim 4.69)
	(envelope-from <std-proposals+bncBDDM34EO6QDRBLOLY25AKGQE56CCUZA@isocpp.org>)
	id 1b8rGB-0008Pg-CE
	for gclcip-std-proposals@m.gmane.org; Fri, 03 Jun 2016 17:43:43 +0200
Original-Received: by mail-pa0-f70.google.com with SMTP id te7sf49899033pab.2
        for <gclcip-std-proposals@m.gmane.org>; Fri, 03 Jun 2016 08:43:42 -0700 (PDT)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=isocpp-org.20150623.gappssmtp.com; s=20150623;
        h=mime-version:in-reply-to:references:from:date:message-id:subject:to
         :x-original-sender:x-original-authentication-results:reply-to
         :precedence:mailing-list:list-id:x-spam-checked-in-group:list-post
         :list-help:list-archive:list-subscribe:list-unsubscribe;
        bh=bbia+Ucw0jbBs7f5Vak2KRYzhYx+HjVNwVr6Las2hI4=;
        b=ytnUVMo1vkN8YE9Fvq1AgU6XPj3QDzaQ9hAgpoEcqNre0FBnsih3v8Z6ncQ2b+T0nK
         KllTdhqAS7yDX+uLqvFmp2FRUvp6YUviXpqIrY99yIlMTM4zM0oVIEHt3daiq4WiF01b
         TL9Z4ySBbscF3SYsoszkrH7yP6bHDlVYWK7gkl8tmP4wPJmGHGFbx7t0FVojWy/KG5yP
         UM6jb8iaFpD6JsHeka0aRzqbva7Ga7fJq62abql9FqGsDGSBANyBi91pTXX7LvKYQQIl
         lkZeTqHSqVvWuues5UB6mIwBfX4J7BA32cBSCIiKti2fpl9KFMrdpn+mnxgOjVot9amA
         COKA==
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=1e100.net; s=20130820;
        h=x-gm-message-state:mime-version:in-reply-to:references:from:date
         :message-id:subject:to:x-original-sender
         :x-original-authentication-results:reply-to:precedence:mailing-list
         :list-id:x-spam-checked-in-group:list-post:list-help:list-archive
         :list-subscribe:list-unsubscribe;
        bh=bbia+Ucw0jbBs7f5Vak2KRYzhYx+HjVNwVr6Las2hI4=;
        b=kIELjCKKVx81IXzYh3LEzzDQAgBgWdfzIcMzaonrmVelVL4H4rBjYR3iX0N+0qrD5Y
         EjRcUW4JxgXipCgXLnhhP3GTilW+7sChEqtNu2pIb783mElgzmWtEPeMDxvJrE9jrvrU
         EA0/zwy/+ba0/TJUw3d8ky0oNRHrZy5u+CSzFu5KxP+lWwtPHf7fF323bsZ4cF+eFoxs
         QOLvzRSU0kAasaEGOgW499Ymw2SAVcEwzSx8r9dP50l2rR3vc3RONIbtaahJvKMYQrqR
         fRm9siDDmZCP0rR8xWrnyDsNiQbQOMsblxL2v8a3brPgl0BijZbigrBsfisZYcyO8PV1
         U8OA==
X-Gm-Message-State: ALyK8tLrgR05vOin9tPWx0N2vBgU2Hx/BfvWsIZusItT6aT7lhRQEL99q3dur90FefiRPg==
X-Received: by 10.66.152.203 with SMTP id va11mr2956871pab.19.1464968622231;
        Fri, 03 Jun 2016 08:43:42 -0700 (PDT)
X-BeenThere: std-proposals@isocpp.org
Original-Received: by 10.107.187.193 with SMTP id l184ls408402iof.29.gmail; Fri, 03 Jun
 2016 08:43:41 -0700 (PDT)
X-Received: by 10.107.128.29 with SMTP id b29mr5065048iod.87.1464968621328;
        Fri, 03 Jun 2016 08:43:41 -0700 (PDT)
Original-Received: from mail-io0-x22c.google.com (mail-io0-x22c.google.com. [2607:f8b0:4001:c06::22c])
        by mx.google.com with ESMTPS id k7si226894ith.5.2016.06.03.08.43.41
        for <std-proposals@isocpp.org>
        (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128);
        Fri, 03 Jun 2016 08:43:41 -0700 (PDT)
Received-SPF: pass (google.com: domain of jyasskin@google.com designates 2607:f8b0:4001:c06::22c as permitted sender) client-ip=2607:f8b0:4001:c06::22c;
Original-Received: by mail-io0-x22c.google.com with SMTP id k19so64685522ioi.3
        for <std-proposals@isocpp.org>; Fri, 03 Jun 2016 08:43:41 -0700 (PDT)
X-Received: by 10.107.149.66 with SMTP id x63mr5927585iod.141.1464968620748;
 Fri, 03 Jun 2016 08:43:40 -0700 (PDT)
Original-Received: by 10.64.225.228 with HTTP; Fri, 3 Jun 2016 08:43:21 -0700 (PDT)
In-Reply-To: <f490fd21-cf07-4d7b-8936-c71c97a1ab9d@isocpp.org>
X-Original-Sender: jyasskin@google.com
X-Original-Authentication-Results: mx.google.com;       dkim=pass
 header.i=@google.com;       spf=pass (google.com: domain of
 jyasskin@google.com designates 2607:f8b0:4001:c06::22c as permitted sender)
 smtp.mailfrom=jyasskin@google.com;       dmarc=pass (p=REJECT dis=NONE) header.from=google.com
X-Original-From: Jeffrey Yasskin <jyasskin@google.com>
Precedence: list
Mailing-list: list std-proposals@isocpp.org; contact std-proposals+owners@isocpp.org
List-ID: <std-proposals.isocpp.org>
X-Spam-Checked-In-Group: std-proposals@isocpp.org
X-Google-Group-Id: 399137483710
List-Post: <https://groups.google.com/a/isocpp.org/group/std-proposals/post>, <mailto:std-proposals@isocpp.org>
List-Help: <https://support.google.com/a/isocpp.org/bin/topic.py?topic=25838>, <mailto:std-proposals+help@isocpp.org>
List-Archive: <https://groups.google.com/a/isocpp.org/group/std-proposals/>
List-Subscribe: <https://groups.google.com/a/isocpp.org/group/std-proposals/subscribe>,
 <mailto:std-proposals+subscribe@isocpp.org>
List-Unsubscribe: <mailto:googlegroups-manage+399137483710+unsubscribe@googlegroups.com>,
 <https://groups.google.com/a/isocpp.org/group/std-proposals/subscribe>
Xref: news.gmane.org gmane.comp.lang.c++.isocpp.proposals:26134
Archived-At: <http://permalink.gmane.org/gmane.comp.lang.c++.isocpp.proposals/26134>

Is this based on an existing library? We're much more likely to adopt
a proposal that's been used widely than one that was invented for the
standard.

On Fri, Jun 3, 2016 at 2:37 AM,  <alexander.zywicki@gmail.com> wrote:
> I have drafted some ideas on how I think the c++ std library could support
> audio functionality.
>
> I know that audio functionality is a very operating specific problem, but
> with the recent trend towards implementing a file-system library and
> possibly a graphics library I believe that audio would not be too much of a
> reach anymore.
>
> Here are some of the ideas I have so far. I have both some code examples of
> the intended usage as well as a list of the types needed to implement the
> given examples.
>
> Please keep in mind my drafts are still very rough.
>
>
> CODE EXAMPLES
>
> //std::audio example 1 "single process"
> void example_1(){
>     double sample_rate = 44100;
>     std::size_t frame_size =2;
>     std::size_t buffer_size=128;
>
>     std::audio_context<float>
> ctx{sample_rate,buffer_size,frame_size};//contruct from values
>
>     std::astream_process<float> proc(ctx,[](std::iastream const& input,
> std::oastream& output){
>         std::frame_buffer<float>& buff = ctx.borrow_buffer();//borrow a
> buffer from the context for usage
>         //prevents the need for dynamic allocation of a temporary buffer
>         input>>buff;//stream data into buffer for manipulation
>         for(auto&& frame: buff){
>             frame=0.0;//do something with audio
>         }
>         output<<buff;//stream to output
>     });//dsp object
>     //uses implied routing equivilent to
>     //std::aout<<proc<<std::ain;
>     //
>
>     proc.start();
>     //do other stuff
>     proc.stop();
> }
>
> //std::audio example 2 "process group"
> void example_2(){
>
>     std::audio_context<float> ctx;//default context created with
> std::default_* values
>
>     //version 1: capture context via lambda
>     std::astream_process<float> proc1(ctx,[&ctx](std::iastream const& input,
> std::oastream& output){
>         std::frame_buffer<float>& buff = ctx.borrow_buffer();
>         input>>buff;
>         for(auto&& frame: buff){
>             frame*=0.5;
>         }
>         output<<buff;
>     });//dsp object
>
>     //version 2: have context passed as argument
>     std::astream_process<float> proc2(ctx,[](std::iastream const& input,
> std::oastream& output,std::audio_context<float> const& context){
>         std::frame_buffer<float>& buff = ctx.borrow_buffer();
>         input>>buff;
>         for(auto&& frame: buff){
>             frame*=2.0;
>         }
>         output<<buff;
>     });
>
>     std::process_group<float> pgroup;//a group of processes that will happen
> consecutivley
>     pgroup.push(proc1);//add to group
>     pgroup.push(proc2);//add to group
>
>     //configure stream relationships in terms of std::ain / std:aout
> manually
>     //std::ain/std::aout are std::astream globals that refer to the default
> audio inputs and outputs supplied by the context in use
>     //std::ain/std::aout will route the audio to the enpoint specified by
> the context reference held by the process that is streaming the data
>     std::aout<<proc1<<proc2<<std::ain;//method 1
>     //std::ain>>proc2>>proc1>>std::aout;//method 2
>
>     pgroup.start();
>     //do other stuff
>     pgroup.stop();
>
> }
>
>
> //std::audio example 3 "audio files"
> void example_3(){
>
>     std::audio_context<float> ctx;
>
>     std::astream_process<float> proc(ctx,[](std::iafstream const& input,
> std::oafstream& output){
>         std::frame_buffer<float>& buff = ctx.borrow_buffer();
>         input>>buff;
>         for(auto&& frame: buff){
>             frame=0.0;
>         }
>         output<<buff;
>     });//dsp object
>
>     std::iafstream audio_file1(ctx,"filename1.extension");//an audio file
> handle
>     std::oafstream audio_file2(ctx,"filename2.extension");//an audio file
> handle
>
>     //routing
>     audio_file2<<proc<<audio_file1;//take input from file nad write to file
>     //audio_file1>>proc>>audio_file2;//equivilent syntax
>     proc.start();
>     //do other stuff
>     proc.stop();
> }
>
>
> //std::audio example 4 "combination routing"
> void example_3(){
>
>     std::audio_context<float> ctx;
>     //manually select hardware endpoints
>     std::size_t device_id = ctx.default_device_id();
>     std::iastream input_device =
> ctx.get_device<std::input_device>(device_id);
>     std::oastream output_device =
> ctx.get_device<std::output_device>(device_id);
>
>     std::astream_process<float> proc(ctx,[](std::iastream const& input,
>                                             std::oastream& output,
>                                             std::iafstream const&
> input_file,
>                                              std::oafstream& output_file){
>         std::frame_buffer<float>& buff = ctx.borrow_buffer();
>         (input + input_file)>>buff;//add streams to perform sum before
> writing to buffer
>         //or you could use seperate buffers
>         //like this
>         /*
>             std::frame_buffer<float> buff1;
>             std::frame_buffer<float> buff2;
>
>             input>>buff1;
>             input_file>>buff2;
>             buff1+=buff2;//buffer arithmatic
>         */
>         output<<buff;//send the contents of buff to the hardware out and the
> file out
>         output_file<<buff;
>     });
>
>     std::iafstream audio_file1(ctx,"filename1.extension");//the actual files
> to be used above
>     std::oafstream audio_file2(ctx,"filename2.extension");
>
>     //connect the files to the process
>     //connect the hardware device to the process
>     audio_file2<<proc<<audio_file1;//take input from file
>     output_device<<proc<<input_device;//also take from hardware
>     proc.start();
>     //do other stuff
>     proc.stop();
> }
>
>
>
> REQUIRED LIBRARY MEMBERS
>
>
> namespace std{
>     inline namespace audio{
>         //working context for audio flow
>         template<typename>
>         class audio_context;
>         /*
>         *The context in which all audio data is centered.
>         *Contains: sampling rate, buffer size, frame size, etc...
>         *The values of ain,aout,afin,afout refer to the endpoints defined by
> the context, when applied to routing on a porocess tied to the context
>         *think of a context as the program level driver object
>         */
>
>         //audio streams (think like std::fstream and its friends)
>         class astream;//audio stream
>         class oastream;//output audio stream
>         class iastream;//input audio stream
>         class oafstream;//output audio file stream
>         class iafstream;//input audio file stream
>
>
>         //stream endpoints
>         class ain;//audio input endpoint
>         class aout;//audio output endpoint
>         class afin;//audio file input endpoint
>         class afout//audio file output endpoint
>
>         //stream processing
>         template<typename>
>         class astream_process;//a dsp process applied to a stream
>
>         template<typename>
>         class process_group;//a group of processes that will act as one
>
>         //containers
>         template<typename>
>         class frame_buffer;//a sequence container that is resizeable at
> runtime, but only with explicit resize calls. contains frames(see below)
>         /*Implementation note on frame_buffer
>          *frame_buffer is intended to hold N number of frames which
> themselves can hold M number of samples
>          *meaning that the total size in samples if frame_buffer = N * M
>          *ideally frame_buffers representation of its sample data will be
> continuous in memory
>         */
>
>         template<typename>
>         class frame;//a container that holds samples, thin array wrapper
>
>
>         //hardware representation
>         class device;//an audio device as recognized by the OS
>         class input_device;//an input device
>         class output_device;//an output device
>
>         // audio file formats
>         enum class afformat{
>             raw,//raw headerless audio bytes, interpreted only by the
> settings of the context.
>             //best used for temporary storage within the life of a context
>             wav,
>             flac//etc...
>         }
>     }
> }
>
>
>
> --
> You received this message because you are subscribed to the Google Groups
> "ISO C++ Standard - Future Proposals" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to std-proposals+unsubscribe@isocpp.org.
> To post to this group, send email to std-proposals@isocpp.org.
> To view this discussion on the web visit
> https://groups.google.com/a/isocpp.org/d/msgid/std-proposals/f490fd21-cf07-4d7b-8936-c71c97a1ab9d%40isocpp.org.

-- 
You received this message because you are subscribed to the Google Groups "ISO C++ Standard - Future Proposals" group.
To unsubscribe from this group and stop receiving emails from it, send an email to std-proposals+unsubscribe@isocpp.org.
To post to this group, send email to std-proposals@isocpp.org.
To view this discussion on the web visit https://groups.google.com/a/isocpp.org/d/msgid/std-proposals/CANh-dX%3DR4Oa0OPZSrL7c9PXGyAdvM2CCBdP9C%2Bh--N4Vt-J%3D9g%40mail.gmail.com.

.
